home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / tools / gcc / gcc270_src.lha / gcc-2.7.0-amiga / config / arm / arm.c next >
Encoding:
C/C++ Source or Header  |  1995-06-15  |  94.7 KB  |  3,751 lines

  1. /* Output routines for GCC for ARM/RISCiX.
  2.    Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
  3.    Contributed by Pieter `Tiggr' Schoenmakers (rcpieter@win.tue.nl)
  4.              and Martin Simmons (@harleqn.co.uk).
  5.    More major hacks by Richard Earnshaw (rwe11@cl.cam.ac.uk)
  6.  
  7. This file is part of GNU CC.
  8.  
  9. GNU CC is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2, or (at your option)
  12. any later version.
  13.  
  14. GNU CC is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with GNU CC; see the file COPYING.  If not, write to
  21. the Free Software Foundation, 59 Temple Place - Suite 330,
  22. Boston, MA 02111-1307, USA.  */
  23.     
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "assert.h"
  27. #include "config.h"
  28. #include "rtl.h"
  29. #include "regs.h"
  30. #include "hard-reg-set.h"
  31. #include "real.h"
  32. #include "insn-config.h"
  33. #include "conditions.h"
  34. #include "insn-flags.h"
  35. #include "output.h"
  36. #include "insn-attr.h"
  37. #include "flags.h"
  38. #include "reload.h"
  39. #include "tree.h"
  40. #include "expr.h"
  41.  
  42. /* The maximum number of insns skipped which will be conditionalised if
  43.    possible.  */
  44. #define MAX_INSNS_SKIPPED  5
  45.  
  46. /* Some function declarations.  */
  47. extern FILE *asm_out_file;
  48. extern char *output_multi_immediate ();
  49. extern void arm_increase_location ();
  50.  
  51. HOST_WIDE_INT int_log2 PROTO ((HOST_WIDE_INT));
  52. static int get_prologue_size PROTO ((void));
  53.  
  54. /*  Define the information needed to generate branch insns.  This is
  55.    stored from the compare operation. */
  56.  
  57. rtx arm_compare_op0, arm_compare_op1;
  58. int arm_compare_fp;
  59.  
  60. /* What type of cpu are we compiling for? */
  61. enum processor_type arm_cpu;
  62.  
  63. /* What type of floating point are we compiling for? */
  64. enum floating_point_type arm_fpu;
  65.  
  66. /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference, we
  67.    must report the mode of the memory reference from PRINT_OPERAND to
  68.    PRINT_OPERAND_ADDRESS.  */
  69. enum machine_mode output_memory_reference_mode;
  70.  
  71. /* Nonzero if the prologue must setup `fp'.  */
  72. int current_function_anonymous_args;
  73.  
  74. /* Location counter of .text segment.  */
  75. int arm_text_location = 0;
  76.  
  77. /* Set to one if we think that lr is only saved because of subroutine calls,
  78.    but all of these can be `put after' return insns */
  79. int lr_save_eliminated;
  80.  
  81. /* A hash table is used to store text segment labels and their associated
  82.    offset from the start of the text segment.  */
  83. struct label_offset
  84. {
  85.   char *name;
  86.   int offset;
  87.   struct label_offset *cdr;
  88. };
  89.  
  90. #define LABEL_HASH_SIZE  257
  91.  
  92. static struct label_offset *offset_table[LABEL_HASH_SIZE];
  93.  
  94. /* Set to 1 when a return insn is output, this means that the epilogue
  95.    is not needed. */
  96.  
  97. static int return_used_this_function;
  98.  
  99. /* For an explanation of these variables, see final_prescan_insn below.  */
  100. int arm_ccfsm_state;
  101. int arm_current_cc;
  102. rtx arm_target_insn;
  103. int arm_target_label;
  104.  
  105. /* The condition codes of the ARM, and the inverse function.  */
  106. char *arm_condition_codes[] =
  107. {
  108.   "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
  109.   "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
  110. };
  111.  
  112. #define ARM_INVERSE_CONDITION_CODE(X)  ((X) ^ 1)
  113.  
  114. /* Return 1 if it is possible to return using a single instruction */
  115.  
  116. int
  117. use_return_insn ()
  118. {
  119.   int regno;
  120.  
  121.   if (!reload_completed ||current_function_pretend_args_size
  122.       || current_function_anonymous_args
  123.       || (get_frame_size () && !(TARGET_APCS || frame_pointer_needed)))
  124.     return 0;
  125.  
  126.   /* Can't be done if any of the FPU regs are pushed, since this also
  127.      requires an insn */
  128.   for (regno = 20; regno < 24; regno++)
  129.     if (regs_ever_live[regno])
  130.       return 0;
  131.  
  132.   return 1;
  133. }
  134.  
  135. /* Return TRUE if int I is a valid immediate ARM constant.  */
  136.  
  137. int
  138. const_ok_for_arm (i)
  139.      HOST_WIDE_INT i;
  140. {
  141.   unsigned HOST_WIDE_INT mask = ~0xFF;
  142.  
  143.   /* Fast return for 0 and powers of 2 */
  144.   if ((i & (i - 1)) == 0)
  145.     return TRUE;
  146.  
  147.   do
  148.     {
  149.       if ((i & mask & (unsigned HOST_WIDE_INT) 0xffffffff) == 0)
  150.         return TRUE;
  151.       mask =
  152.       (mask << 2) | ((mask & (unsigned HOST_WIDE_INT) 0xffffffff)
  153.              >> (32 - 2)) | ~((unsigned HOST_WIDE_INT) 0xffffffff);
  154.     } while (mask != ~0xFF);
  155.  
  156.   return FALSE;
  157. }
  158.  
  159. /* Return true if I is a valid constant for the operation CODE. */
  160. int
  161. const_ok_for_op (i, code, mode)
  162.      HOST_WIDE_INT i;
  163.      enum rtx_code code;
  164.      enum machine_mode mode;
  165. {
  166.   if (const_ok_for_arm (i))
  167.     return 1;
  168.  
  169.   switch (code)
  170.     {
  171.     case PLUS:
  172.       return const_ok_for_arm (ARM_SIGN_EXTEND (-i));
  173.  
  174.     case MINUS:        /* Should only occur with (MINUS I reg) => rsb */
  175.     case XOR:
  176.     case IOR:
  177.       return 0;
  178.  
  179.     case AND:
  180.       return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
  181.  
  182.     default:
  183.       abort ();
  184.     }
  185. }
  186.  
  187. /* Emit a sequence of insns to handle a large constant.
  188.    CODE is the code of the operation required, it can be any of SET, PLUS,
  189.    IOR, AND, XOR, MINUS;
  190.    MODE is the mode in which the operation is being performed;
  191.    VAL is the integer to operate on;
  192.    SOURCE is the other operand (a register, or a null-pointer for SET);
  193.    SUBTARGETS means it is safe to create scratch registers if that will
  194.    either produce a simpler sequence, or we will want to cse the values. */
  195.  
  196. int
  197. arm_split_constant (code, mode, val, target, source, subtargets)
  198.      enum rtx_code code;
  199.      enum machine_mode mode;
  200.      HOST_WIDE_INT val;
  201.      rtx target;
  202.      rtx source;
  203.      int subtargets;
  204. {
  205.   int can_add = 0;
  206.   int can_invert = 0;
  207.   int can_negate = 0;
  208.   int can_negate_initial = 0;
  209.   int can_shift = 0;
  210.   int i;
  211.   int num_bits_set = 0;
  212.   int set_sign_bit_copies = 0;
  213.   int clear_sign_bit_copies = 0;
  214.   int clear_zero_bit_copies = 0;
  215.   int set_zero_bit_copies = 0;
  216.   int insns = 0;
  217.   rtx new_src;
  218.   unsigned HOST_WIDE_INT temp1, temp2;
  219.   unsigned HOST_WIDE_INT remainder = val & 0xffffffff;
  220.  
  221.   /* find out which operations are safe for a given CODE.  Also do a quick
  222.      check for degenerate cases; these can occur when DImode operations
  223.      are split.  */
  224.   switch (code)
  225.     {
  226.     case SET:
  227.       can_invert = 1;
  228.       can_shift = 1;
  229.       can_negate = 1;
  230.       break;
  231.  
  232.     case PLUS:
  233.       can_negate = 1;
  234.       can_negate_initial = 1;
  235.       break;
  236.  
  237.     case IOR:
  238.       if (remainder == 0xffffffff)
  239.     {
  240.       emit_insn (gen_rtx (SET, VOIDmode, target,
  241.                   GEN_INT (ARM_SIGN_EXTEND (val))));
  242.       return 1;
  243.     }
  244.       if (remainder == 0)
  245.     {
  246.       if (reload_completed && rtx_equal_p (target, source))
  247.         return 0;
  248.       emit_insn (gen_rtx (SET, VOIDmode, target, source));
  249.       return 1;
  250.     }
  251.       break;
  252.  
  253.     case AND:
  254.       if (remainder == 0)
  255.     {
  256.       emit_insn (gen_rtx (SET, VOIDmode, target, const0_rtx));
  257.       return 1;
  258.     }
  259.       if (remainder == 0xffffffff)
  260.     {
  261.       if (reload_completed && rtx_equal_p (target, source))
  262.         return 0;
  263.       emit_insn (gen_rtx (SET, VOIDmode, target, source));
  264.       return 1;
  265.     }
  266.       can_invert = 1;
  267.       break;
  268.  
  269.     case XOR:
  270.       if (remainder == 0)
  271.     {
  272.       if (reload_completed && rtx_equal_p (target, source))
  273.         return 0;
  274.       emit_insn (gen_rtx (SET, VOIDmode, target, source));
  275.       return 1;
  276.     }
  277.       if (remainder == 0xffffffff)
  278.     {
  279.       emit_insn (gen_rtx (SET, VOIDmode, target,
  280.                   gen_rtx (NOT, mode, source)));
  281.       return 1;
  282.     }
  283.  
  284.       /* We don't know how to handle this yet below.  */
  285.       abort ();
  286.  
  287.     case MINUS:
  288.       /* We treat MINUS as (val - source), since (source - val) is always
  289.      passed as (source + (-val)).  */
  290.       if (remainder == 0)
  291.     {
  292.       emit_insn (gen_rtx (SET, VOIDmode, target,
  293.                   gen_rtx (NEG, mode, source)));
  294.       return 1;
  295.     }
  296.       if (const_ok_for_arm (val))
  297.     {
  298.       emit_insn (gen_rtx (SET, VOIDmode, target, 
  299.                   gen_rtx (MINUS, mode, GEN_INT (val), source)));
  300.       return 1;
  301.     }
  302.       can_negate = 1;
  303.  
  304.       break;
  305.  
  306.     default:
  307.       abort ();
  308.     }
  309.  
  310.   /* If we can do it in one insn get out quickly */
  311.   if (const_ok_for_arm (val)
  312.       || (can_negate_initial && const_ok_for_arm (-val))
  313.       || (can_invert && const_ok_for_arm (~val)))
  314.     {
  315.       emit_insn (gen_rtx (SET, VOIDmode, target,
  316.               (source ? gen_rtx (code, mode, source,
  317.                          GEN_INT (val)) : GEN_INT (val))));
  318.       return 1;
  319.     }
  320.  
  321.  
  322.   /* Calculate a few attributes that may be useful for specific
  323.      optimizations. */
  324.  
  325.   for (i = 31; i >= 0; i--)
  326.     {
  327.       if ((remainder & (1 << i)) == 0)
  328.     clear_sign_bit_copies++;
  329.       else
  330.     break;
  331.     }
  332.  
  333.   for (i = 31; i >= 0; i--)
  334.     {
  335.       if ((remainder & (1 << i)) != 0)
  336.     set_sign_bit_copies++;
  337.       else
  338.     break;
  339.     }
  340.  
  341.   for (i = 0; i <= 31; i++)
  342.     {
  343.       if ((remainder & (1 << i)) == 0)
  344.     clear_zero_bit_copies++;
  345.       else
  346.     break;
  347.     }
  348.  
  349.   for (i = 0; i <= 31; i++)
  350.     {
  351.       if ((remainder & (1 << i)) != 0)
  352.     set_zero_bit_copies++;
  353.       else
  354.     break;
  355.     }
  356.  
  357.   switch (code)
  358.     {
  359.     case SET:
  360.       /* See if we can do this by sign_extending a constant that is known
  361.      to be negative.  This is a good, way of doing it, since the shift
  362.      may well merge into a subsequent insn.  */
  363.       if (set_sign_bit_copies > 1)
  364.     {
  365.       if (const_ok_for_arm
  366.           (temp1 = ARM_SIGN_EXTEND (remainder 
  367.                     << (set_sign_bit_copies - 1))))
  368.         {
  369.           new_src = subtargets ? gen_reg_rtx (mode) : target;
  370.           emit_insn (gen_rtx (SET, VOIDmode, new_src, GEN_INT (temp1)));
  371.           emit_insn (gen_ashrsi3 (target, new_src, 
  372.                       GEN_INT (set_sign_bit_copies - 1)));
  373.           return 2;
  374.         }
  375.       /* For an inverted constant, we will need to set the low bits,
  376.          these will be shifted out of harm's way.  */
  377.       temp1 |= (1 << (set_sign_bit_copies - 1)) - 1;
  378.       if (const_ok_for_arm (~temp1))
  379.         {
  380.           new_src = subtargets ? gen_reg_rtx (mode) : target;
  381.           emit_insn (gen_rtx (SET, VOIDmode, new_src, GEN_INT (temp1)));
  382.           emit_insn (gen_ashrsi3 (target, new_src, 
  383.                       GEN_INT (set_sign_bit_copies - 1)));
  384.           return 2;
  385.         }
  386.     }
  387.  
  388.       /* See if we can generate this by setting the bottom (or the top)
  389.      16 bits, and then shifting these into the other half of the
  390.      word.  We only look for the simplest cases, to do more would cost
  391.      too much.  Be careful, however, not to generate this when the
  392.      alternative would take fewer insns.  */
  393.       if (val & 0xffff0000)
  394.     {
  395.       temp1 = remainder & 0xffff0000;
  396.       temp2 = remainder & 0x0000ffff;
  397.  
  398.       /* Overlaps outside this range are best done using other methods. */
  399.       for (i = 9; i < 24; i++)
  400.         {
  401.           if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder)
  402.           && ! const_ok_for_arm (temp2))
  403.         {
  404.           insns
  405.             = arm_split_constant (code, mode, temp2,
  406.                       (new_src
  407.                        = subtargets ? gen_reg_rtx (mode)
  408.                        : target),
  409.                       source, subtargets);
  410.           source = new_src;
  411.           emit_insn (gen_rtx (SET, VOIDmode, target,
  412.                       gen_rtx (IOR, mode,
  413.                            gen_rtx (ASHIFT, mode, source,
  414.                             GEN_INT (i)),
  415.                            source)));
  416.           return insns + 1;
  417.         }
  418.         }
  419.  
  420.       /* Don't duplicate cases already considered. */
  421.       for (i = 17; i < 24; i++)
  422.         {
  423.           if (((temp1 | (temp1 >> i)) == remainder)
  424.           && ! const_ok_for_arm (temp1))
  425.         {
  426.           insns
  427.             = arm_split_constant (code, mode, temp1,
  428.                       (new_src
  429.                        = subtargets ? gen_reg_rtx (mode)
  430.                        : target),
  431.                       source, subtargets);
  432.           source = new_src;
  433.           emit_insn (gen_rtx (SET, VOIDmode, target,
  434.                       gen_rtx (IOR, mode,
  435.                            gen_rtx (LSHIFTRT, mode, source,
  436.                             GEN_INT (i)),
  437.                            source)));
  438.           return insns + 1;
  439.         }
  440.         }
  441.     }
  442.       break;
  443.  
  444.     case IOR:
  445.     case XOR:
  446.       /* If we have IOR or XOR, and the inverse of the constant can be loaded
  447.      in a single instruction, and we can find a temporary to put it in,
  448.      then this can be done in two instructions instead of 3-4.  */
  449.       if (subtargets
  450.       || (reload_completed && ! reg_mentioned_p (target, source)))
  451.     {
  452.       if (const_ok_for_arm (ARM_SIGN_EXTEND (~ val)))
  453.         {
  454.           rtx sub = subtargets ? gen_reg_rtx (mode) : target;
  455.  
  456.           emit_insn (gen_rtx (SET, VOIDmode, sub,
  457.                   GEN_INT (ARM_SIGN_EXTEND (~ val))));
  458.           emit_insn (gen_rtx (SET, VOIDmode, target, 
  459.                   gen_rtx (code, mode, source, sub)));
  460.           return 2;
  461.         }
  462.     }
  463.  
  464.       if (code == XOR)
  465.     break;
  466.  
  467.       if (set_sign_bit_copies > 8
  468.       && (val & (-1 << (32 - set_sign_bit_copies))) == val)
  469.     {
  470.       rtx sub = subtargets ? gen_reg_rtx (mode) : target;
  471.       rtx shift = GEN_INT (set_sign_bit_copies);
  472.  
  473.       emit_insn (gen_rtx (SET, VOIDmode, sub,
  474.                   gen_rtx (NOT, mode, 
  475.                        gen_rtx (ASHIFT, mode, source, 
  476.                         shift))));
  477.       emit_insn (gen_rtx (SET, VOIDmode, target,
  478.                   gen_rtx (NOT, mode,
  479.                        gen_rtx (LSHIFTRT, mode, sub,
  480.                         shift))));
  481.       return 2;
  482.     }
  483.  
  484.       if (set_zero_bit_copies > 8
  485.       && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder)
  486.     {
  487.       rtx sub = subtargets ? gen_reg_rtx (mode) : target;
  488.       rtx shift = GEN_INT (set_zero_bit_copies);
  489.       
  490.       emit_insn (gen_rtx (SET, VOIDmode, sub,
  491.                   gen_rtx (NOT, mode,
  492.                        gen_rtx (LSHIFTRT, mode, source,
  493.                         shift))));
  494.       emit_insn (gen_rtx (SET, VOIDmode, target,
  495.                   gen_rtx (NOT, mode,
  496.                        gen_rtx (ASHIFT, mode, sub,
  497.                         shift))));
  498.       return 2;
  499.     }
  500.  
  501.       if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~ val)))
  502.     {
  503.       rtx sub = subtargets ? gen_reg_rtx (mode) : target;
  504.       emit_insn (gen_rtx (SET, VOIDmode, sub,
  505.                   gen_rtx (NOT, mode, source)));
  506.       source = sub;
  507.       if (subtargets)
  508.         sub = gen_reg_rtx (mode);
  509.       emit_insn (gen_rtx (SET, VOIDmode, sub,
  510.                   gen_rtx (AND, mode, source, GEN_INT (temp1))));
  511.       emit_insn (gen_rtx (SET, VOIDmode, target,
  512.                   gen_rtx (NOT, mode, sub)));
  513.       return 3;
  514.     }
  515.       break;
  516.  
  517.     case AND:
  518.       /* See if two shifts will do 2 or more insn's worth of work.  */
  519.       if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24)
  520.     {
  521.       HOST_WIDE_INT shift_mask = ((0xffffffff 
  522.                        << (32 - clear_sign_bit_copies))
  523.                       & 0xffffffff);
  524.       rtx new_source;
  525.       rtx shift = GEN_INT (clear_sign_bit_copies);
  526.  
  527.       if ((remainder | shift_mask) != 0xffffffff)
  528.         {
  529.           new_source = subtargets ? gen_reg_rtx (mode) : target;
  530.           insns = arm_split_constant (AND, mode, remainder | shift_mask,
  531.                       new_source, source, subtargets);
  532.           source = new_source;
  533.         }
  534.  
  535.       new_source = subtargets ? gen_reg_rtx (mode) : target;
  536.       emit_insn (gen_ashlsi3 (new_source, source, shift));
  537.       emit_insn (gen_lshrsi3 (target, new_source, shift));
  538.       return insns + 2;
  539.     }
  540.  
  541.       if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24)
  542.     {
  543.       HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1;
  544.       rtx new_source;
  545.       rtx shift = GEN_INT (clear_zero_bit_copies);
  546.       
  547.       if ((remainder | shift_mask) != 0xffffffff)
  548.         {
  549.           new_source = subtargets ? gen_reg_rtx (mode) : target;
  550.           insns = arm_split_constant (AND, mode, remainder | shift_mask,
  551.                       new_source, source, subtargets);
  552.           source = new_source;
  553.         }
  554.  
  555.       new_source = subtargets ? gen_reg_rtx (mode) : target;
  556.       emit_insn (gen_lshrsi3 (new_source, source, shift));
  557.       emit_insn (gen_ashlsi3 (target, new_source, shift));
  558.       return insns + 2;
  559.     }
  560.  
  561.       break;
  562.  
  563.     default:
  564.       break;
  565.     }
  566.  
  567.   for (i = 0; i < 32; i++)
  568.     if (remainder & (1 << i))
  569.       num_bits_set++;
  570.  
  571.   if (code == AND || (can_invert && num_bits_set > 16))
  572.     remainder = (~remainder) & 0xffffffff;
  573.   else if (code == PLUS && num_bits_set > 16)
  574.     remainder = (-remainder) & 0xffffffff;
  575.   else
  576.     {
  577.       can_invert = 0;
  578.       can_negate = 0;
  579.     }
  580.  
  581.   /* Now try and find a way of doing the job in either two or three
  582.      instructions.
  583.      We start by looking for the largest block of zeros that are aligned on
  584.      a 2-bit boundary, we then fill up the temps, wrapping around to the
  585.      top of the word when we drop off the bottom.
  586.      In the worst case this code should produce no more than four insns. */
  587.   {
  588.     int best_start = 0;
  589.     int best_consecutive_zeros = 0;
  590.  
  591.     for (i = 0; i < 32; i += 2)
  592.       {
  593.     int consecutive_zeros = 0;
  594.  
  595.     if (! (remainder & (3 << i)))
  596.       {
  597.         while ((i < 32) && ! (remainder & (3 << i)))
  598.           {
  599.         consecutive_zeros += 2;
  600.         i += 2;
  601.           }
  602.         if (consecutive_zeros > best_consecutive_zeros)
  603.           {
  604.         best_consecutive_zeros = consecutive_zeros;
  605.         best_start = i - consecutive_zeros;
  606.           }
  607.         i -= 2;
  608.       }
  609.       }
  610.  
  611.     /* Now start emitting the insns, starting with the one with the highest
  612.        bit set: we do this so that the smallest number will be emitted last;
  613.        this is more likely to be combinable with addressing insns. */
  614.     i = best_start;
  615.     do
  616.       {
  617.     int end;
  618.  
  619.     if (i <= 0)
  620.       i += 32;
  621.     if (remainder & (3 << (i - 2)))
  622.       {
  623.         end = i - 8;
  624.         if (end < 0)
  625.           end += 32;
  626.         temp1 = remainder & ((0x0ff << end)
  627.                  | ((i < end) ? (0xff >> (32 - end)) : 0));
  628.         remainder &= ~temp1;
  629.  
  630.         if (code == SET)
  631.           {
  632.         emit_insn (gen_rtx (SET, VOIDmode,
  633.                     new_src = (subtargets ? gen_reg_rtx (mode)
  634.                            : target),
  635.                     GEN_INT (can_invert ? ~temp1 : temp1)));
  636.         can_invert = 0;
  637.         code = PLUS;
  638.           }
  639.         else if (code == MINUS)
  640.           {
  641.         emit_insn (gen_rtx (SET, VOIDmode,
  642.                     new_src = (subtargets ? gen_reg_rtx (mode)
  643.                            : target),
  644.                     gen_rtx (code, mode, GEN_INT (temp1),
  645.                          source)));
  646.         code = PLUS;
  647.           }
  648.         else
  649.           {
  650.         emit_insn (gen_rtx (SET, VOIDmode,
  651.                     new_src = remainder ? (subtargets
  652.                                ? gen_reg_rtx (mode)
  653.                                : target) : target,
  654.                     gen_rtx (code, mode, source,
  655.                          GEN_INT (can_invert ? ~temp1
  656.                               : (can_negate
  657.                              ? -temp1 : temp1)))));
  658.           }
  659.  
  660.         insns++;
  661.         source = new_src;
  662.         i -= 6;
  663.       }
  664.     i -= 2;
  665.       } while (remainder);
  666.   }
  667.   return insns;
  668. }
  669.  
  670. #define REG_OR_SUBREG_REG(X)                        \
  671.   (GET_CODE (X) == REG                            \
  672.    || (GET_CODE (X) == SUBREG && GET_CODE (SUBREG_REG (X)) == REG))
  673.  
  674. #define REG_OR_SUBREG_RTX(X)            \
  675.    (GET_CODE (X) == REG ? (X) : SUBREG_REG (X))
  676.  
  677. #define ARM_FRAME_RTX(X)                \
  678.   ((X) == frame_pointer_rtx || (X) == stack_pointer_rtx    \
  679.    || (X) == arg_pointer_rtx)
  680.  
  681. int
  682. arm_rtx_costs (x, code, outer_code)
  683.      rtx x;
  684.      enum rtx_code code, outer_code;
  685. {
  686.   enum machine_mode mode = GET_MODE (x);
  687.   enum rtx_code subcode;
  688.   int extra_cost;
  689.  
  690.   switch (code)
  691.     {
  692.     case MEM:
  693.       /* Memory costs quite a lot for the first word, but subsequent words
  694.      load at the equivalent of a single insn each.  */
  695.       return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD)
  696.           + (CONSTANT_POOL_ADDRESS_P (x) ? 4 : 0));
  697.  
  698.     case DIV:
  699.     case MOD:
  700.       return 100;
  701.  
  702.     case ROTATE:
  703.       if (mode == SImode && GET_CODE (XEXP (x, 1)) == REG)
  704.     return 4;
  705.       /* Fall through */
  706.     case ROTATERT:
  707.       if (mode != SImode)
  708.     return 8;
  709.       /* Fall through */
  710.     case ASHIFT: case LSHIFTRT: case ASHIFTRT:
  711.       if (mode == DImode)
  712.     return (8 + (GET_CODE (XEXP (x, 1)) == CONST_INT ? 0 : 8)
  713.         + ((GET_CODE (XEXP (x, 0)) == REG 
  714.             || (GET_CODE (XEXP (x, 0)) == SUBREG
  715.             && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG))
  716.            ? 0 : 8));
  717.       return (1 + ((GET_CODE (XEXP (x, 0)) == REG
  718.             || (GET_CODE (XEXP (x, 0)) == SUBREG
  719.             && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG))
  720.            ? 0 : 4)
  721.           + ((GET_CODE (XEXP (x, 1)) == REG
  722.           || (GET_CODE (XEXP (x, 1)) == SUBREG
  723.               && GET_CODE (SUBREG_REG (XEXP (x, 1))) == REG)
  724.           || (GET_CODE (XEXP (x, 1)) == CONST_INT))
  725.          ? 0 : 4));
  726.  
  727.     case MINUS:
  728.       if (mode == DImode)
  729.     return (4 + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : 8)
  730.         + ((REG_OR_SUBREG_REG (XEXP (x, 0))
  731.             || (GET_CODE (XEXP (x, 0)) == CONST_INT
  732.                && const_ok_for_arm (INTVAL (XEXP (x, 0)))))
  733.            ? 0 : 8));
  734.  
  735.       if (GET_MODE_CLASS (mode) == MODE_FLOAT)
  736.     return (2 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
  737.               || (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
  738.               && const_double_rtx_ok_for_fpu (XEXP (x, 1))))
  739.              ? 0 : 8)
  740.         + ((REG_OR_SUBREG_REG (XEXP (x, 0))
  741.             || (GET_CODE (XEXP (x, 0)) == CONST_DOUBLE
  742.             && const_double_rtx_ok_for_fpu (XEXP (x, 0))))
  743.            ? 0 : 8));
  744.  
  745.       if (((GET_CODE (XEXP (x, 0)) == CONST_INT
  746.         && const_ok_for_arm (INTVAL (XEXP (x, 0)))
  747.         && REG_OR_SUBREG_REG (XEXP (x, 1))))
  748.       || (((subcode = GET_CODE (XEXP (x, 1))) == ASHIFT
  749.            || subcode == ASHIFTRT || subcode == LSHIFTRT
  750.            || subcode == ROTATE || subcode == ROTATERT
  751.            || (subcode == MULT
  752.            && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
  753.            && ((INTVAL (XEXP (XEXP (x, 1), 1)) &
  754.             (INTVAL (XEXP (XEXP (x, 1), 1)) - 1)) == 0)))
  755.           && REG_OR_SUBREG_REG (XEXP (XEXP (x, 1), 0))
  756.           && (REG_OR_SUBREG_REG (XEXP (XEXP (x, 1), 1))
  757.           || GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT)
  758.           && REG_OR_SUBREG_REG (XEXP (x, 0))))
  759.     return 1;
  760.       /* Fall through */
  761.  
  762.     case PLUS: 
  763.       if (GET_MODE_CLASS (mode) == MODE_FLOAT)
  764.     return (2 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 8)
  765.         + ((REG_OR_SUBREG_REG (XEXP (x, 1))
  766.             || (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
  767.             && const_double_rtx_ok_for_fpu (XEXP (x, 1))))
  768.            ? 0 : 8));
  769.  
  770.       /* Fall through */
  771.     case AND: case XOR: case IOR: 
  772.       extra_cost = 0;
  773.  
  774.       /* Normally the frame registers will be spilt into reg+const during
  775.      reload, so it is a bad idea to combine them with other instructions,
  776.      since then they might not be moved outside of loops.  As a compromise
  777.      we allow integration with ops that have a constant as their second
  778.      operand.  */
  779.       if ((REG_OR_SUBREG_REG (XEXP (x, 0))
  780.        && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0)))
  781.        && GET_CODE (XEXP (x, 1)) != CONST_INT)
  782.       || (REG_OR_SUBREG_REG (XEXP (x, 0))
  783.           && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0)))))
  784.     extra_cost = 4;
  785.  
  786.       if (mode == DImode)
  787.     return (4 + extra_cost + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 8)
  788.         + ((REG_OR_SUBREG_REG (XEXP (x, 1))
  789.             || (GET_CODE (XEXP (x, 1)) == CONST_INT
  790.             && const_ok_for_op (INTVAL (XEXP (x, 1)), code, mode)))
  791.            ? 0 : 8));
  792.  
  793.       if (REG_OR_SUBREG_REG (XEXP (x, 0)))
  794.     return (1 + (GET_CODE (XEXP (x, 1)) == CONST_INT ? 0 : extra_cost)
  795.         + ((REG_OR_SUBREG_REG (XEXP (x, 1))
  796.             || (GET_CODE (XEXP (x, 1)) == CONST_INT
  797.             && const_ok_for_op (INTVAL (XEXP (x, 1)), code, mode)))
  798.            ? 0 : 4));
  799.  
  800.       else if (REG_OR_SUBREG_REG (XEXP (x, 1)))
  801.     return (1 + extra_cost
  802.         + ((((subcode = GET_CODE (XEXP (x, 0))) == ASHIFT
  803.              || subcode == LSHIFTRT || subcode == ASHIFTRT
  804.              || subcode == ROTATE || subcode == ROTATERT
  805.              || (subcode == MULT
  806.              && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  807.              && ((INTVAL (XEXP (XEXP (x, 0), 1)) &
  808.                   (INTVAL (XEXP (XEXP (x, 0), 1)) - 1)) == 0))
  809.             && (REG_OR_SUBREG_REG (XEXP (XEXP (x, 0), 0)))
  810.             && ((REG_OR_SUBREG_REG (XEXP (XEXP (x, 0), 1)))
  811.             || GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)))
  812.            ? 0 : 4));
  813.  
  814.       return 8;
  815.  
  816.     case MULT:
  817.       if (GET_MODE_CLASS (mode) == MODE_FLOAT
  818.       || mode == DImode)
  819.     return 30;
  820.  
  821.       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
  822.     {
  823.       HOST_WIDE_INT i = INTVAL (XEXP (x, 1)) & 0xffffffff;
  824.       int add_cost = const_ok_for_arm (i) ? 4 : 8;
  825.       int j;
  826.       
  827.       /* This will need adjusting for ARM's with fast multiplies */
  828.       for (j = 0; i && j < 32; j += 2)
  829.         {
  830.           i &= ~(3 << j);
  831.           add_cost += 2;
  832.         }
  833.  
  834.       return add_cost;
  835.     }
  836.  
  837.       return (30 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4)
  838.           + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : 4));
  839.  
  840.     case NEG:
  841.       if (GET_MODE_CLASS (mode) == MODE_FLOAT)
  842.     return 4 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 6);
  843.       /* Fall through */
  844.     case NOT:
  845.       if (mode == DImode)
  846.     return 4 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4);
  847.  
  848.       return 1 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4);
  849.  
  850.     case IF_THEN_ELSE:
  851.       if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC)
  852.     return 14;
  853.       return 2;
  854.  
  855.     case COMPARE:
  856.       return 1;
  857.  
  858.     case ABS:
  859.       return 4 + (mode == DImode ? 4 : 0);
  860.  
  861.     case SIGN_EXTEND:
  862.       if (GET_MODE (XEXP (x, 0)) == QImode)
  863.     return (4 + (mode == DImode ? 4 : 0)
  864.         + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
  865.       /* Fall through */
  866.     case ZERO_EXTEND:
  867.       switch (GET_MODE (XEXP (x, 0)))
  868.     {
  869.     case QImode:
  870.       return (1 + (mode == DImode ? 4 : 0)
  871.           + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
  872.  
  873.     case HImode:
  874.       return (4 + (mode == DImode ? 4 : 0)
  875.           + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
  876.  
  877.     case SImode:
  878.       return (1 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
  879.     }
  880.       abort ();
  881.  
  882.     default:
  883.       return 99;
  884.     }
  885. }
  886.      
  887. /* This code has been fixed for cross compilation. */
  888.  
  889. static int fpa_consts_inited = 0;
  890.  
  891. char *strings_fpa[8] = {
  892.   "0.0",
  893.   "1.0",
  894.   "2.0",
  895.   "3.0",
  896.   "4.0",
  897.   "5.0",
  898.   "0.5",
  899.   "10.0"
  900.   };
  901.  
  902. static REAL_VALUE_TYPE values_fpa[8];
  903.  
  904. static void
  905. init_fpa_table ()
  906. {
  907.   int i;
  908.   REAL_VALUE_TYPE r;
  909.  
  910.   for (i = 0; i < 8; i++)
  911.     {
  912.       r = REAL_VALUE_ATOF (strings_fpa[i], DFmode);
  913.       values_fpa[i] = r;
  914.     }
  915.  
  916.   fpa_consts_inited = 1;
  917. }
  918.  
  919. /* Return TRUE if rtx X is a valid immediate FPU constant. */
  920.  
  921. int
  922. const_double_rtx_ok_for_fpu (x)
  923.      rtx x;
  924. {
  925.   REAL_VALUE_TYPE r;
  926.   int i;
  927.   
  928.   if (!fpa_consts_inited)
  929.     init_fpa_table ();
  930.   
  931.   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  932.   if (REAL_VALUE_MINUS_ZERO (r))
  933.     return 0;
  934.  
  935.   for (i = 0; i < 8; i++)
  936.     if (REAL_VALUES_EQUAL (r, values_fpa[i]))
  937.       return 1;
  938.  
  939.   return 0;
  940. }
  941.  
  942. /* Return TRUE if rtx X is a valid immediate FPU constant. */
  943.  
  944. int
  945. neg_const_double_rtx_ok_for_fpu (x)
  946.      rtx x;
  947. {
  948.   REAL_VALUE_TYPE r;
  949.   int i;
  950.   
  951.   if (!fpa_consts_inited)
  952.     init_fpa_table ();
  953.   
  954.   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  955.   r = REAL_VALUE_NEGATE (r);
  956.   if (REAL_VALUE_MINUS_ZERO (r))
  957.     return 0;
  958.  
  959.   for (i = 0; i < 8; i++)
  960.     if (REAL_VALUES_EQUAL (r, values_fpa[i]))
  961.       return 1;
  962.  
  963.   return 0;
  964. }
  965.  
  966. /* Predicates for `match_operand' and `match_operator'.  */
  967.  
  968. /* s_register_operand is the same as register_operand, but it doesn't accept
  969.    (SUBREG (MEM)...). */
  970.  
  971. int
  972. s_register_operand (op, mode)
  973.      register rtx op;
  974.      enum machine_mode mode;
  975. {
  976.   if (GET_MODE (op) != mode && mode != VOIDmode)
  977.     return 0;
  978.  
  979.   if (GET_CODE (op) == SUBREG)
  980.     op = SUBREG_REG (op);
  981.  
  982.   /* We don't consider registers whose class is NO_REGS
  983.      to be a register operand.  */
  984.   return (GET_CODE (op) == REG
  985.       && (REGNO (op) >= FIRST_PSEUDO_REGISTER
  986.           || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
  987. }
  988.  
  989. /* Only accept reg, subreg(reg), const_int.  */
  990.  
  991. int
  992. reg_or_int_operand (op, mode)
  993.      register rtx op;
  994.      enum machine_mode mode;
  995. {
  996.   if (GET_CODE (op) == CONST_INT)
  997.     return 1;
  998.  
  999.   if (GET_MODE (op) != mode && mode != VOIDmode)
  1000.     return 0;
  1001.  
  1002.   if (GET_CODE (op) == SUBREG)
  1003.     op = SUBREG_REG (op);
  1004.  
  1005.   /* We don't consider registers whose class is NO_REGS
  1006.      to be a register operand.  */
  1007.   return (GET_CODE (op) == REG
  1008.       && (REGNO (op) >= FIRST_PSEUDO_REGISTER
  1009.           || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
  1010. }
  1011.  
  1012. /* Return 1 if OP is an item in memory, given that we are in reload.  */
  1013.  
  1014. int
  1015. reload_memory_operand (op, mode)
  1016.      rtx op;
  1017.      enum machine_mode mode;
  1018. {
  1019.   int regno = true_regnum (op);
  1020.  
  1021.   return (! CONSTANT_P (op)
  1022.       && (regno == -1
  1023.           || (GET_CODE (op) == REG
  1024.           && REGNO (op) >= FIRST_PSEUDO_REGISTER)));
  1025. }
  1026.  
  1027. /* Return TRUE for valid operands for the rhs of an ARM instruction.  */
  1028.  
  1029. int
  1030. arm_rhs_operand (op, mode)
  1031.      rtx op;
  1032.      enum machine_mode mode;
  1033. {
  1034.   return (s_register_operand (op, mode)
  1035.       || (GET_CODE (op) == CONST_INT && const_ok_for_arm (INTVAL (op))));
  1036. }
  1037.  
  1038. /* Return TRUE for valid operands for the rhs of an ARM instruction, or a load.
  1039.  */
  1040.  
  1041. int
  1042. arm_rhsm_operand (op, mode)
  1043.      rtx op;
  1044.      enum machine_mode mode;
  1045. {
  1046.   return (s_register_operand (op, mode)
  1047.       || (GET_CODE (op) == CONST_INT && const_ok_for_arm (INTVAL (op)))
  1048.       || memory_operand (op, mode));
  1049. }
  1050.  
  1051. /* Return TRUE for valid operands for the rhs of an ARM instruction, or if a
  1052.    constant that is valid when negated.  */
  1053.  
  1054. int
  1055. arm_add_operand (op, mode)
  1056.      rtx op;
  1057.      enum machine_mode mode;
  1058. {
  1059.   return (s_register_operand (op, mode)
  1060.       || (GET_CODE (op) == CONST_INT
  1061.           && (const_ok_for_arm (INTVAL (op))
  1062.           || const_ok_for_arm (-INTVAL (op)))));
  1063. }
  1064.  
  1065. int
  1066. arm_not_operand (op, mode)
  1067.      rtx op;
  1068.      enum machine_mode mode;
  1069. {
  1070.   return (s_register_operand (op, mode)
  1071.       || (GET_CODE (op) == CONST_INT
  1072.           && (const_ok_for_arm (INTVAL (op))
  1073.           || const_ok_for_arm (~INTVAL (op)))));
  1074. }
  1075.  
  1076. /* Return TRUE for valid operands for the rhs of an FPU instruction.  */
  1077.  
  1078. int
  1079. fpu_rhs_operand (op, mode)
  1080.      rtx op;
  1081.      enum machine_mode mode;
  1082. {
  1083.   if (s_register_operand (op, mode))
  1084.     return TRUE;
  1085.   else if (GET_CODE (op) == CONST_DOUBLE)
  1086.     return (const_double_rtx_ok_for_fpu (op));
  1087.  
  1088.   return FALSE;
  1089. }
  1090.  
  1091. int
  1092. fpu_add_operand (op, mode)
  1093.      rtx op;
  1094.      enum machine_mode mode;
  1095. {
  1096.   if (s_register_operand (op, mode))
  1097.     return TRUE;
  1098.   else if (GET_CODE (op) == CONST_DOUBLE)
  1099.     return (const_double_rtx_ok_for_fpu (op) 
  1100.         || neg_const_double_rtx_ok_for_fpu (op));
  1101.  
  1102.   return FALSE;
  1103. }
  1104.  
  1105. /* Return nonzero if OP is a constant power of two.  */
  1106.  
  1107. int
  1108. power_of_two_operand (op, mode)
  1109.      rtx op;
  1110.      enum machine_mode mode;
  1111. {
  1112.   if (GET_CODE (op) == CONST_INT)
  1113.     {
  1114.       HOST_WIDE_INT value = INTVAL(op);
  1115.       return value != 0  &&  (value & (value - 1)) == 0;
  1116.     }
  1117.   return FALSE;
  1118. }
  1119.  
  1120. /* Return TRUE for a valid operand of a DImode operation.
  1121.    Either: REG, CONST_DOUBLE or MEM(DImode_address).
  1122.    Note that this disallows MEM(REG+REG), but allows
  1123.    MEM(PRE/POST_INC/DEC(REG)).  */
  1124.  
  1125. int
  1126. di_operand (op, mode)
  1127.      rtx op;
  1128.      enum machine_mode mode;
  1129. {
  1130.   if (s_register_operand (op, mode))
  1131.     return TRUE;
  1132.  
  1133.   switch (GET_CODE (op))
  1134.     {
  1135.     case CONST_DOUBLE:
  1136.     case CONST_INT:
  1137.       return TRUE;
  1138.  
  1139.     case MEM:
  1140.       return memory_address_p (DImode, XEXP (op, 0));
  1141.  
  1142.     default:
  1143.       return FALSE;
  1144.     }
  1145. }
  1146.  
  1147. /* Return TRUE for a valid operand of a DFmode operation when -msoft-float.
  1148.    Either: REG, CONST_DOUBLE or MEM(DImode_address).
  1149.    Note that this disallows MEM(REG+REG), but allows
  1150.    MEM(PRE/POST_INC/DEC(REG)).  */
  1151.  
  1152. int
  1153. soft_df_operand (op, mode)
  1154.      rtx op;
  1155.      enum machine_mode mode;
  1156. {
  1157.   if (s_register_operand (op, mode))
  1158.     return TRUE;
  1159.  
  1160.   switch (GET_CODE (op))
  1161.     {
  1162.     case CONST_DOUBLE:
  1163.       return TRUE;
  1164.  
  1165.     case MEM:
  1166.       return memory_address_p (DFmode, XEXP (op, 0));
  1167.  
  1168.     default:
  1169.       return FALSE;
  1170.     }
  1171. }
  1172.  
  1173. /* Return TRUE for valid index operands. */
  1174.  
  1175. int
  1176. index_operand (op, mode)
  1177.      rtx op;
  1178.      enum machine_mode mode;
  1179. {
  1180.   return (s_register_operand(op, mode)
  1181.       || (immediate_operand (op, mode)
  1182.           && INTVAL (op) < 4096 && INTVAL (op) > -4096));
  1183. }
  1184.  
  1185. /* Return TRUE for valid shifts by a constant. This also accepts any
  1186.    power of two on the (somewhat overly relaxed) assumption that the
  1187.    shift operator in this case was a mult. */
  1188.  
  1189. int
  1190. const_shift_operand (op, mode)
  1191.      rtx op;
  1192.      enum machine_mode mode;
  1193. {
  1194.   return (power_of_two_operand (op, mode)
  1195.       || (immediate_operand (op, mode)
  1196.           && (INTVAL (op) < 32 && INTVAL (op) > 0)));
  1197. }
  1198.  
  1199. /* Return TRUE for arithmetic operators which can be combined with a multiply
  1200.    (shift).  */
  1201.  
  1202. int
  1203. shiftable_operator (x, mode)
  1204.      rtx x;
  1205.      enum machine_mode mode;
  1206. {
  1207.   if (GET_MODE (x) != mode)
  1208.     return FALSE;
  1209.   else
  1210.     {
  1211.       enum rtx_code code = GET_CODE (x);
  1212.  
  1213.       return (code == PLUS || code == MINUS
  1214.           || code == IOR || code == XOR || code == AND);
  1215.     }
  1216. }
  1217.  
  1218. /* Return TRUE for shift operators. */
  1219.  
  1220. int
  1221. shift_operator (x, mode)
  1222.      rtx x;
  1223.      enum machine_mode mode;
  1224. {
  1225.   if (GET_MODE (x) != mode)
  1226.     return FALSE;
  1227.   else
  1228.     {
  1229.       enum rtx_code code = GET_CODE (x);
  1230.  
  1231.       if (code == MULT)
  1232.     return power_of_two_operand (XEXP (x, 1));
  1233.  
  1234.       return (code == ASHIFT || code == ASHIFTRT || code == LSHIFTRT
  1235.           || code == ROTATERT);
  1236.     }
  1237. }
  1238.  
  1239. int equality_operator (x, mode)
  1240.      rtx x;
  1241.      enum machine_mode mode;
  1242. {
  1243.   return GET_CODE (x) == EQ || GET_CODE (x) == NE;
  1244. }
  1245.  
  1246. /* Return TRUE for SMIN SMAX UMIN UMAX operators. */
  1247.  
  1248. int
  1249. minmax_operator (x, mode)
  1250.      rtx x;
  1251.      enum machine_mode mode;
  1252. {
  1253.   enum rtx_code code = GET_CODE (x);
  1254.  
  1255.   if (GET_MODE (x) != mode)
  1256.     return FALSE;
  1257.  
  1258.   return code == SMIN || code == SMAX || code == UMIN || code == UMAX;
  1259. }
  1260.  
  1261. /* return TRUE if x is EQ or NE */
  1262.  
  1263. /* Return TRUE if this is the condition code register, if we aren't given
  1264.    a mode, accept any class CCmode register */
  1265.  
  1266. int
  1267. cc_register (x, mode)
  1268.      rtx x;
  1269.      enum machine_mode mode;
  1270. {
  1271.   if (mode == VOIDmode)
  1272.     {
  1273.       mode = GET_MODE (x);
  1274.       if (GET_MODE_CLASS (mode) != MODE_CC)
  1275.     return FALSE;
  1276.     }
  1277.  
  1278.   if (mode == GET_MODE (x) && GET_CODE (x) == REG && REGNO (x) == 24)
  1279.     return TRUE;
  1280.  
  1281.   return FALSE;
  1282. }
  1283.  
  1284. /* Return TRUE if this is the condition code register, if we aren't given
  1285.    a mode, accept any mode in class CC_MODE that is reversible */
  1286.  
  1287. int
  1288. reversible_cc_register (x, mode)
  1289.      rtx x;
  1290.      enum machine_mode mode;
  1291. {
  1292.   if (mode == VOIDmode)
  1293.     {
  1294.       mode = GET_MODE (x);
  1295.       if (GET_MODE_CLASS (mode) != MODE_CC
  1296.       && GET_CODE (x) == REG && REGNO (x) == 24)
  1297.     abort ();
  1298.       if (GET_MODE_CLASS (mode) != MODE_CC
  1299.       || (! flag_fast_math && ! REVERSIBLE_CC_MODE (mode)))
  1300.     return FALSE;
  1301.     }
  1302.  
  1303.   if (mode == GET_MODE (x) && GET_CODE (x) == REG && REGNO (x) == 24)
  1304.     return TRUE;
  1305.  
  1306.   return FALSE;
  1307. }
  1308.  
  1309. enum rtx_code
  1310. minmax_code (x)
  1311.      rtx x;
  1312. {
  1313.   enum rtx_code code = GET_CODE (x);
  1314.  
  1315.   if (code == SMAX)
  1316.     return GE;
  1317.   else if (code == SMIN)
  1318.     return LE;
  1319.   else if (code == UMIN)
  1320.     return LEU;
  1321.   else if (code == UMAX)
  1322.     return GEU;
  1323.  
  1324.   abort ();
  1325. }
  1326.  
  1327. /* Return 1 if memory locations are adjacent */
  1328.  
  1329. int
  1330. adjacent_mem_locations (a, b)
  1331.      rtx a, b;
  1332. {
  1333.   int val0 = 0, val1 = 0;
  1334.   int reg0, reg1;
  1335.   
  1336.   if ((GET_CODE (XEXP (a, 0)) == REG
  1337.        || (GET_CODE (XEXP (a, 0)) == PLUS
  1338.        && GET_CODE (XEXP (XEXP (a, 0), 1)) == CONST_INT))
  1339.       && (GET_CODE (XEXP (b, 0)) == REG
  1340.       || (GET_CODE (XEXP (b, 0)) == PLUS
  1341.           && GET_CODE (XEXP (XEXP (b, 0), 1)) == CONST_INT)))
  1342.     {
  1343.       if (GET_CODE (XEXP (a, 0)) == PLUS)
  1344.         {
  1345.       reg0 = REGNO (XEXP (XEXP (a, 0), 0));
  1346.       val0 = INTVAL (XEXP (XEXP (a, 0), 1));
  1347.         }
  1348.       else
  1349.     reg0 = REGNO (XEXP (a, 0));
  1350.       if (GET_CODE (XEXP (b, 0)) == PLUS)
  1351.         {
  1352.       reg1 = REGNO (XEXP (XEXP (b, 0), 0));
  1353.       val1 = INTVAL (XEXP (XEXP (b, 0), 1));
  1354.         }
  1355.       else
  1356.     reg1 = REGNO (XEXP (b, 0));
  1357.       return (reg0 == reg1) && ((val1 - val0) == 4 || (val0 - val1) == 4);
  1358.     }
  1359.   return 0;
  1360. }
  1361.  
  1362. /* Return 1 if OP is a load multiple operation.  It is known to be
  1363.    parallel and the first section will be tested. */
  1364.  
  1365. int
  1366. load_multiple_operation (op, mode)
  1367.      rtx op;
  1368.      enum machine_mode mode;
  1369. {
  1370.   HOST_WIDE_INT count = XVECLEN (op, 0);
  1371.   int dest_regno;
  1372.   rtx src_addr;
  1373.   HOST_WIDE_INT i = 1, base = 0;
  1374.   rtx elt;
  1375.  
  1376.   if (count <= 1
  1377.       || GET_CODE (XVECEXP (op, 0, 0)) != SET)
  1378.     return 0;
  1379.  
  1380.   /* Check to see if this might be a write-back */
  1381.   if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS)
  1382.     {
  1383.       i++;
  1384.       base = 1;
  1385.  
  1386.       /* Now check it more carefully */
  1387.       if (GET_CODE (SET_DEST (elt)) != REG
  1388.           || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG
  1389.           || REGNO (XEXP (SET_SRC (elt), 0)) != REGNO (SET_DEST (elt))
  1390.           || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT
  1391.           || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 2) * 4
  1392.           || GET_CODE (XVECEXP (op, 0, count - 1)) != CLOBBER
  1393.           || GET_CODE (XEXP (XVECEXP (op, 0, count - 1), 0)) != REG
  1394.           || REGNO (XEXP (XVECEXP (op, 0, count - 1), 0))
  1395.               != REGNO (SET_DEST (elt)))
  1396.         return 0;
  1397.  
  1398.       count--;
  1399.     }
  1400.  
  1401.   /* Perform a quick check so we don't blow up below.  */
  1402.   if (count <= i
  1403.       || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
  1404.       || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != REG
  1405.       || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != MEM)
  1406.     return 0;
  1407.  
  1408.   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, i - 1)));
  1409.   src_addr = XEXP (SET_SRC (XVECEXP (op, 0, i - 1)), 0);
  1410.  
  1411.   for (; i < count; i++)
  1412.     {
  1413.       rtx elt = XVECEXP (op, 0, i);
  1414.  
  1415.       if (GET_CODE (elt) != SET
  1416.           || GET_CODE (SET_DEST (elt)) != REG
  1417.           || GET_MODE (SET_DEST (elt)) != SImode
  1418.           || REGNO (SET_DEST (elt)) != dest_regno + i - base
  1419.           || GET_CODE (SET_SRC (elt)) != MEM
  1420.           || GET_MODE (SET_SRC (elt)) != SImode
  1421.           || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
  1422.           || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
  1423.           || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
  1424.           || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != (i - base) * 4)
  1425.         return 0;
  1426.     }
  1427.  
  1428.   return 1;
  1429. }
  1430.  
  1431. /* Return 1 if OP is a store multiple operation.  It is known to be
  1432.    parallel and the first section will be tested. */
  1433.  
  1434. int
  1435. store_multiple_operation (op, mode)
  1436.      rtx op;
  1437.      enum machine_mode mode;
  1438. {
  1439.   HOST_WIDE_INT count = XVECLEN (op, 0);
  1440.   int src_regno;
  1441.   rtx dest_addr;
  1442.   HOST_WIDE_INT i = 1, base = 0;
  1443.   rtx elt;
  1444.  
  1445.   if (count <= 1
  1446.       || GET_CODE (XVECEXP (op, 0, 0)) != SET)
  1447.     return 0;
  1448.  
  1449.   /* Check to see if this might be a write-back */
  1450.   if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS)
  1451.     {
  1452.       i++;
  1453.       base = 1;
  1454.  
  1455.       /* Now check it more carefully */
  1456.       if (GET_CODE (SET_DEST (elt)) != REG
  1457.           || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG
  1458.           || REGNO (XEXP (SET_SRC (elt), 0)) != REGNO (SET_DEST (elt))
  1459.           || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT
  1460.           || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 2) * 4
  1461.           || GET_CODE (XVECEXP (op, 0, count - 1)) != CLOBBER
  1462.           || GET_CODE (XEXP (XVECEXP (op, 0, count - 1), 0)) != REG
  1463.           || REGNO (XEXP (XVECEXP (op, 0, count - 1), 0))
  1464.               != REGNO (SET_DEST (elt)))
  1465.         return 0;
  1466.  
  1467.       count--;
  1468.     }
  1469.  
  1470.   /* Perform a quick check so we don't blow up below.  */
  1471.   if (count <= i
  1472.       || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
  1473.       || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != MEM
  1474.       || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != REG)
  1475.     return 0;
  1476.  
  1477.   src_regno = REGNO (SET_SRC (XVECEXP (op, 0, i - 1)));
  1478.   dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, i - 1)), 0);
  1479.  
  1480.   for (; i < count; i++)
  1481.     {
  1482.       elt = XVECEXP (op, 0, i);
  1483.  
  1484.       if (GET_CODE (elt) != SET
  1485.           || GET_CODE (SET_SRC (elt)) != REG
  1486.           || GET_MODE (SET_SRC (elt)) != SImode
  1487.           || REGNO (SET_SRC (elt)) != src_regno + i - base
  1488.           || GET_CODE (SET_DEST (elt)) != MEM
  1489.           || GET_MODE (SET_DEST (elt)) != SImode
  1490.           || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
  1491.           || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
  1492.           || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
  1493.           || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != (i - base) * 4)
  1494.         return 0;
  1495.     }
  1496.  
  1497.   return 1;
  1498. }
  1499.  
  1500. int
  1501. multi_register_push (op, mode)
  1502.      rtx op;
  1503.      enum machine_mode mode;
  1504. {
  1505.   if (GET_CODE (op) != PARALLEL
  1506.       || (GET_CODE (XVECEXP (op, 0, 0)) != SET)
  1507.       || (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC)
  1508.       || (XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != 2))
  1509.     return 0;
  1510.  
  1511.   return 1;
  1512. }
  1513.  
  1514.  
  1515. /* Routines for use with attributes */
  1516.  
  1517. int
  1518. const_pool_offset (symbol)
  1519.      rtx symbol;
  1520. {
  1521.   return get_pool_offset (symbol) - get_pool_size () - get_prologue_size ();
  1522. }
  1523.  
  1524. /* Routines for use in generating RTL */
  1525.  
  1526. rtx
  1527. arm_gen_load_multiple (base_regno, count, from, up, write_back)
  1528.      int base_regno;
  1529.      int count;
  1530.      rtx from;
  1531.      int up;
  1532.      int write_back;
  1533. {
  1534.   int i = 0, j;
  1535.   rtx result;
  1536.   int sign = up ? 1 : -1;
  1537.  
  1538.   result = gen_rtx (PARALLEL, VOIDmode,
  1539.                     rtvec_alloc (count + (write_back ? 2 : 0)));
  1540.   if (write_back)
  1541.     {
  1542.       XVECEXP (result, 0, 0)
  1543.     = gen_rtx (SET, GET_MODE (from), from,
  1544.            plus_constant (from, count * 4 * sign));
  1545.       i = 1;
  1546.       count++;
  1547.     }
  1548.  
  1549.   for (j = 0; i < count; i++, j++)
  1550.     {
  1551.       XVECEXP (result, 0, i)
  1552.     = gen_rtx (SET, VOIDmode, gen_rtx (REG, SImode, base_regno + j),
  1553.            gen_rtx (MEM, SImode,
  1554.                 plus_constant (from, j * 4 * sign)));
  1555.     }
  1556.  
  1557.   if (write_back)
  1558.     XVECEXP (result, 0, i) = gen_rtx (CLOBBER, SImode, from);
  1559.  
  1560.   return result;
  1561. }
  1562.  
  1563. rtx
  1564. arm_gen_store_multiple (base_regno, count, to, up, write_back)
  1565.      int base_regno;
  1566.      int count;
  1567.      rtx to;
  1568.      int up;
  1569.      int write_back;
  1570. {
  1571.   int i = 0, j;
  1572.   rtx result;
  1573.   int sign = up ? 1 : -1;
  1574.  
  1575.   result = gen_rtx (PARALLEL, VOIDmode,
  1576.                     rtvec_alloc (count + (write_back ? 2 : 0)));
  1577.   if (write_back)
  1578.     {
  1579.       XVECEXP (result, 0, 0)
  1580.     = gen_rtx (SET, GET_MODE (to), to,
  1581.            plus_constant (to, count * 4 * sign));
  1582.       i = 1;
  1583.       count++;
  1584.     }
  1585.  
  1586.   for (j = 0; i < count; i++, j++)
  1587.     {
  1588.       XVECEXP (result, 0, i)
  1589.     = gen_rtx (SET, VOIDmode,
  1590.            gen_rtx (MEM, SImode, plus_constant (to, j * 4 * sign)),
  1591.            gen_rtx (REG, SImode, base_regno + j));
  1592.     }
  1593.  
  1594.   if (write_back)
  1595.     XVECEXP (result, 0, i) = gen_rtx (CLOBBER, SImode, to);
  1596.  
  1597.   return result;
  1598. }
  1599.  
  1600. int
  1601. arm_gen_movstrqi (operands)
  1602.      rtx *operands;
  1603. {
  1604.   HOST_WIDE_INT in_words_to_go, out_words_to_go, last_bytes;
  1605.   int i, r;
  1606.   rtx const_sxteen = gen_rtx (CONST_INT, SImode, 16);
  1607.   rtx src, dst;
  1608.   rtx st_src, st_dst, end_src, end_dst, fin_src, fin_dst;
  1609.   rtx part_bytes_reg = NULL;
  1610.   extern int optimize;
  1611.  
  1612.   if (GET_CODE (operands[2]) != CONST_INT
  1613.       || GET_CODE (operands[3]) != CONST_INT
  1614.       || INTVAL (operands[2]) > 64
  1615.       || INTVAL (operands[3]) & 3)
  1616.     return 0;
  1617.  
  1618.   st_dst = XEXP (operands[0], 0);
  1619.   st_src = XEXP (operands[1], 0);
  1620.   fin_dst = dst = copy_to_mode_reg (SImode, st_dst);
  1621.   fin_src = src = copy_to_mode_reg (SImode, st_src);
  1622.  
  1623.   in_words_to_go = (INTVAL (operands[2]) + 3) / 4;
  1624.   out_words_to_go = INTVAL (operands[2]) / 4;
  1625.   last_bytes = INTVAL (operands[2]) & 3;
  1626.  
  1627.   if (out_words_to_go != in_words_to_go && ((in_words_to_go - 1) & 3) != 0)
  1628.     part_bytes_reg = gen_rtx (REG, SImode, (in_words_to_go - 1) & 3);
  1629.  
  1630.   for (i = 0; in_words_to_go >= 2; i+=4)
  1631.     {
  1632.       emit_insn (arm_gen_load_multiple (0, (in_words_to_go > 4 
  1633.                         ? 4 : in_words_to_go),
  1634.                                         src, TRUE, TRUE));
  1635.       if (out_words_to_go)
  1636.     {
  1637.       if (out_words_to_go != 1)
  1638.         emit_insn (arm_gen_store_multiple (0, (out_words_to_go > 4
  1639.                            ? 4 : out_words_to_go),
  1640.                            dst, TRUE, TRUE));
  1641.       else
  1642.         {
  1643.           emit_move_insn (gen_rtx (MEM, SImode, dst),
  1644.                   gen_rtx (REG, SImode, 0));
  1645.           emit_insn (gen_addsi3 (dst, dst, GEN_INT (4)));
  1646.         }
  1647.     }
  1648.  
  1649.       in_words_to_go -= in_words_to_go < 4 ? in_words_to_go : 4;
  1650.       out_words_to_go -= out_words_to_go < 4 ? out_words_to_go : 4;
  1651.     }
  1652.  
  1653.   /* OUT_WORDS_TO_GO will be zero here if there are byte stores to do.  */
  1654.   if (out_words_to_go)
  1655.   {
  1656.     rtx sreg;
  1657.  
  1658.     emit_move_insn (sreg = gen_reg_rtx (SImode), gen_rtx (MEM, SImode, src));
  1659.     emit_move_insn (fin_src = gen_reg_rtx (SImode), plus_constant (src, 4));
  1660.     emit_move_insn (gen_rtx (MEM, SImode, dst), sreg);
  1661.     emit_move_insn (fin_dst = gen_reg_rtx (SImode), plus_constant (dst, 4));
  1662.     in_words_to_go--;
  1663.  
  1664.     if (in_words_to_go)    /* Sanity check */
  1665.       abort ();
  1666.   }
  1667.  
  1668.   if (in_words_to_go)
  1669.     {
  1670.       if (in_words_to_go < 0)
  1671.     abort ();
  1672.  
  1673.       part_bytes_reg = copy_to_mode_reg (SImode, gen_rtx (MEM, SImode, src));
  1674.       emit_insn (gen_addsi3 (src, src, GEN_INT (4)));
  1675.     }
  1676.  
  1677.   if (BYTES_BIG_ENDIAN && last_bytes)
  1678.     {
  1679.       rtx tmp = gen_reg_rtx (SImode);
  1680.  
  1681.       if (part_bytes_reg == NULL)
  1682.     abort ();
  1683.  
  1684.       /* The bytes we want are in the top end of the word */
  1685.       emit_insn (gen_lshrsi3 (tmp, part_bytes_reg,
  1686.                   GEN_INT (8 * (4 - last_bytes))));
  1687.       part_bytes_reg = tmp;
  1688.       
  1689.       while (last_bytes)
  1690.     {
  1691.       emit_move_insn (gen_rtx (MEM, QImode, 
  1692.                    plus_constant (dst, last_bytes - 1)),
  1693.               gen_rtx (SUBREG, QImode, part_bytes_reg, 0));
  1694.       if (--last_bytes)
  1695.         {
  1696.           tmp = gen_reg_rtx (SImode);
  1697.           emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (8)));
  1698.           part_bytes_reg = tmp;
  1699.         }
  1700.     }
  1701.       
  1702.     }
  1703.   else
  1704.     {
  1705.       while (last_bytes)
  1706.     {
  1707.       if (part_bytes_reg == NULL)
  1708.         abort ();
  1709.  
  1710.       emit_move_insn (gen_rtx (MEM, QImode, dst),
  1711.               gen_rtx (SUBREG, QImode, part_bytes_reg, 0));
  1712.       emit_insn (gen_addsi3 (dst, dst, const1_rtx));
  1713.       if (--last_bytes)
  1714.         {
  1715.           rtx tmp = gen_reg_rtx (SImode);
  1716.           emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (8)));
  1717.           part_bytes_reg = tmp;
  1718.         }
  1719.     }
  1720.     }
  1721.  
  1722.   return 1;
  1723. }
  1724.  
  1725. /* X and Y are two things to compare using CODE.  Emit the compare insn and
  1726.    return the rtx for register 0 in the proper mode.  FP means this is a
  1727.    floating point compare: I don't think that it is needed on the arm.  */
  1728.  
  1729. rtx
  1730. gen_compare_reg (code, x, y, fp)
  1731.      enum rtx_code code;
  1732.      rtx x, y;
  1733. {
  1734.   enum machine_mode mode = SELECT_CC_MODE (code, x, y);
  1735.   rtx cc_reg = gen_rtx (REG, mode, 24);
  1736.  
  1737.   emit_insn (gen_rtx (SET, VOIDmode, cc_reg,
  1738.                       gen_rtx (COMPARE, mode, x, y)));
  1739.  
  1740.   return cc_reg;
  1741. }
  1742.  
  1743. void
  1744. arm_reload_in_hi (operands)
  1745.      rtx *operands;
  1746. {
  1747.   rtx base = find_replacement (&XEXP (operands[1], 0));
  1748.  
  1749.   emit_insn (gen_zero_extendqisi2 (operands[2], gen_rtx (MEM, QImode, base)));
  1750.   emit_insn (gen_zero_extendqisi2 (gen_rtx (SUBREG, SImode, operands[0], 0),
  1751.                    gen_rtx (MEM, QImode, 
  1752.                         plus_constant (base, 1))));
  1753.   if (BYTES_BIG_ENDIAN)
  1754.     emit_insn (gen_rtx (SET, VOIDmode, gen_rtx (SUBREG, SImode, 
  1755.                         operands[0], 0),
  1756.             gen_rtx (IOR, SImode, 
  1757.                  gen_rtx (ASHIFT, SImode,
  1758.                       gen_rtx (SUBREG, SImode,
  1759.                            operands[0], 0),
  1760.                       GEN_INT (8)),
  1761.                  operands[2])));
  1762.   else
  1763.     emit_insn (gen_rtx (SET, VOIDmode, gen_rtx (SUBREG, SImode, 
  1764.                         operands[0], 0),
  1765.             gen_rtx (IOR, SImode, 
  1766.                  gen_rtx (ASHIFT, SImode,
  1767.                       operands[2],
  1768.                       GEN_INT (8)),
  1769.                  gen_rtx (SUBREG, SImode, operands[0], 0))));
  1770. }
  1771.  
  1772. void
  1773. arm_reload_out_hi (operands)
  1774.      rtx *operands;
  1775. {
  1776.   rtx base = find_replacement (&XEXP (operands[0], 0));
  1777.  
  1778.   if (BYTES_BIG_ENDIAN)
  1779.     {
  1780.       emit_insn (gen_movqi (gen_rtx (MEM, QImode, plus_constant (base, 1)),
  1781.                 gen_rtx (SUBREG, QImode, operands[1], 0)));
  1782.       emit_insn (gen_lshrsi3 (operands[2],
  1783.                   gen_rtx (SUBREG, SImode, operands[1], 0),
  1784.                   GEN_INT (8)));
  1785.       emit_insn (gen_movqi (gen_rtx (MEM, QImode, base),
  1786.                 gen_rtx (SUBREG, QImode, operands[2], 0)));
  1787.     }
  1788.   else
  1789.     {
  1790.       emit_insn (gen_movqi (gen_rtx (MEM, QImode, base),
  1791.                 gen_rtx (SUBREG, QImode, operands[1], 0)));
  1792.       emit_insn (gen_lshrsi3 (operands[2],
  1793.                   gen_rtx (SUBREG, SImode, operands[1], 0),
  1794.                   GEN_INT (8)));
  1795.       emit_insn (gen_movqi (gen_rtx (MEM, QImode, plus_constant (base, 1)),
  1796.                 gen_rtx (SUBREG, QImode, operands[2], 0)));
  1797.     }
  1798. }
  1799.  
  1800. /* Check to see if a branch is forwards or backwards.  Return TRUE if it
  1801.    is backwards.  */
  1802.  
  1803. int
  1804. arm_backwards_branch (from, to)
  1805.      int from, to;
  1806. {
  1807.   return insn_addresses[to] <= insn_addresses[from];
  1808. }
  1809.  
  1810. /* Check to see if a branch is within the distance that can be done using
  1811.    an arithmetic expression. */
  1812. int
  1813. short_branch (from, to)
  1814.      int from, to;
  1815. {
  1816.   int delta = insn_addresses[from] + 8 - insn_addresses[to];
  1817.  
  1818.   return abs (delta) < 980;    /* A small margin for safety */
  1819. }
  1820.  
  1821. /* Check to see that the insn isn't the target of the conditionalizing
  1822.    code */
  1823. int
  1824. arm_insn_not_targeted (insn)
  1825.      rtx insn;
  1826. {
  1827.   return insn != arm_target_insn;
  1828. }
  1829.  
  1830.  
  1831. /* Routines to output assembly language.  */
  1832.  
  1833. /* If the rtx is the correct value then return the string of the number.
  1834.    In this way we can ensure that valid double constants are generated even
  1835.    when cross compiling. */
  1836. char *
  1837. fp_immediate_constant (x)
  1838.      rtx x;
  1839. {
  1840.   REAL_VALUE_TYPE r;
  1841.   int i;
  1842.   
  1843.   if (!fpa_consts_inited)
  1844.     init_fpa_table ();
  1845.   
  1846.   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  1847.   for (i = 0; i < 8; i++)
  1848.     if (REAL_VALUES_EQUAL (r, values_fpa[i]))
  1849.       return strings_fpa[i];
  1850.  
  1851.   abort ();
  1852. }
  1853.  
  1854. /* As for fp_immediate_constant, but value is passed directly, not in rtx.  */
  1855. static char *
  1856. fp_const_from_val (r)
  1857.      REAL_VALUE_TYPE *r;
  1858. {
  1859.   int i;
  1860.  
  1861.   if (! fpa_consts_inited)
  1862.     init_fpa_table ();
  1863.  
  1864.   for (i = 0; i < 8; i++)
  1865.     if (REAL_VALUES_EQUAL (*r, values_fpa[i]))
  1866.       return strings_fpa[i];
  1867.  
  1868.   abort ();
  1869. }
  1870.  
  1871. /* Output the operands of a LDM/STM instruction to STREAM.
  1872.    MASK is the ARM register set mask of which only bits 0-15 are important.
  1873.    INSTR is the possibly suffixed base register.  HAT unequals zero if a hat
  1874.    must follow the register list.  */
  1875.  
  1876. void
  1877. print_multi_reg (stream, instr, mask, hat)
  1878.      FILE *stream;
  1879.      char *instr;
  1880.      int mask, hat;
  1881. {
  1882.   int i;
  1883.   int not_first = FALSE;
  1884.  
  1885.   fputc ('\t', stream);
  1886.   fprintf (stream, instr, REGISTER_PREFIX);
  1887.   fputs (", {", stream);
  1888.   for (i = 0; i < 16; i++)
  1889.     if (mask & (1 << i))
  1890.       {
  1891.     if (not_first)
  1892.       fprintf (stream, ", ");
  1893.     fprintf (stream, "%s%s", REGISTER_PREFIX, reg_names[i]);
  1894.     not_first = TRUE;
  1895.       }
  1896.  
  1897.   fprintf (stream, "}%s\n", hat ? "^" : "");
  1898. }
  1899.  
  1900. /* Output a 'call' insn. */
  1901.  
  1902. char *
  1903. output_call (operands)
  1904.      rtx *operands;
  1905. {
  1906.   /* Handle calls to lr using ip (which may be clobbered in subr anyway). */
  1907.  
  1908.   if (REGNO (operands[0]) == 14)
  1909.     {
  1910.       operands[0] = gen_rtx (REG, SImode, 12);
  1911.       output_asm_insn ("mov%?\t%0, %|lr", operands);
  1912.     }
  1913.   output_asm_insn ("mov%?\t%|lr, %|pc", operands);
  1914.   output_asm_insn ("mov%?\t%|pc, %0", operands);
  1915.   return "";
  1916. }
  1917.  
  1918. static int
  1919. eliminate_lr2ip (x)
  1920.      rtx *x;
  1921. {
  1922.   int something_changed = 0;
  1923.   rtx x0 = *x;
  1924.   int code = GET_CODE (x0);
  1925.   register int i, j;
  1926.   register char *fmt;
  1927.   
  1928.   switch (code)
  1929.     {
  1930.     case REG:
  1931.       if (REGNO (x0) == 14)
  1932.         {
  1933.       *x = gen_rtx (REG, SImode, 12);
  1934.       return 1;
  1935.         }
  1936.       return 0;
  1937.     default:
  1938.       /* Scan through the sub-elements and change any references there */
  1939.       fmt = GET_RTX_FORMAT (code);
  1940.       for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1941.     if (fmt[i] == 'e')
  1942.       something_changed |= eliminate_lr2ip (&XEXP (x0, i));
  1943.     else if (fmt[i] == 'E')
  1944.       for (j = 0; j < XVECLEN (x0, i); j++)
  1945.         something_changed |= eliminate_lr2ip (&XVECEXP (x0, i, j));
  1946.       return something_changed;
  1947.     }
  1948. }
  1949.   
  1950. /* Output a 'call' insn that is a reference in memory. */
  1951.  
  1952. char *
  1953. output_call_mem (operands)
  1954.      rtx *operands;
  1955. {
  1956.   operands[0] = copy_rtx (operands[0]); /* Be ultra careful */
  1957.   /* Handle calls using lr by using ip (which may be clobbered in subr anyway).
  1958.    */
  1959.   if (eliminate_lr2ip (&operands[0]))
  1960.     output_asm_insn ("mov%?\t%|ip, %|lr", operands);
  1961.  
  1962.   output_asm_insn ("mov%?\t%|lr, %|pc", operands);
  1963.   output_asm_insn ("ldr%?\t%|pc, %0", operands);
  1964.   return "";
  1965. }
  1966.  
  1967.  
  1968. /* Output a move from arm registers to an fpu registers.
  1969.    OPERANDS[0] is an fpu register.
  1970.    OPERANDS[1] is the first registers of an arm register pair.  */
  1971.  
  1972. char *
  1973. output_mov_long_double_fpu_from_arm (operands)
  1974.      rtx *operands;
  1975. {
  1976.   int arm_reg0 = REGNO (operands[1]);
  1977.   rtx ops[3];
  1978.  
  1979.   if (arm_reg0 == 12)
  1980.     abort();
  1981.  
  1982.   ops[0] = gen_rtx (REG, SImode, arm_reg0);
  1983.   ops[1] = gen_rtx (REG, SImode, 1 + arm_reg0);
  1984.   ops[2] = gen_rtx (REG, SImode, 2 + arm_reg0);
  1985.   
  1986.   output_asm_insn ("stm%?fd\t%|sp!, {%0, %1, %2}", ops);
  1987.   output_asm_insn ("ldf%?e\t%0, [%|sp], #12", operands);
  1988.   return "";
  1989. }
  1990.  
  1991. /* Output a move from an fpu register to arm registers.
  1992.    OPERANDS[0] is the first registers of an arm register pair.
  1993.    OPERANDS[1] is an fpu register.  */
  1994.  
  1995. char *
  1996. output_mov_long_double_arm_from_fpu (operands)
  1997.      rtx *operands;
  1998. {
  1999.   int arm_reg0 = REGNO (operands[0]);
  2000.   rtx ops[3];
  2001.  
  2002.   if (arm_reg0 == 12)
  2003.     abort();
  2004.  
  2005.   ops[0] = gen_rtx (REG, SImode, arm_reg0);
  2006.   ops[1] = gen_rtx (REG, SImode, 1 + arm_reg0);
  2007.   ops[2] = gen_rtx (REG, SImode, 2 + arm_reg0);
  2008.  
  2009.   output_asm_insn ("stf%?e\t%1, [%|sp, #-12]!", operands);
  2010.   output_asm_insn ("ldm%?fd\t%|sp!, {%0, %1, %2}", ops);
  2011.   return "";
  2012. }
  2013.  
  2014. /* Output a move from arm registers to arm registers of a long double
  2015.    OPERANDS[0] is the destination.
  2016.    OPERANDS[1] is the source.  */
  2017. char *
  2018. output_mov_long_double_arm_from_arm (operands)
  2019.      rtx *operands;
  2020. {
  2021.   /* We have to be careful here because the two might overlap */
  2022.   int dest_start = REGNO (operands[0]);
  2023.   int src_start = REGNO (operands[1]);
  2024.   rtx ops[2];
  2025.   int i;
  2026.  
  2027.   if (dest_start < src_start)
  2028.     {
  2029.       for (i = 0; i < 3; i++)
  2030.     {
  2031.       ops[0] = gen_rtx (REG, SImode, dest_start + i);
  2032.       ops[1] = gen_rtx (REG, SImode, src_start + i);
  2033.       output_asm_insn ("mov%?\t%0, %1", ops);
  2034.     }
  2035.     }
  2036.   else
  2037.     {
  2038.       for (i = 2; i >= 0; i--)
  2039.     {
  2040.       ops[0] = gen_rtx (REG, SImode, dest_start + i);
  2041.       ops[1] = gen_rtx (REG, SImode, src_start + i);
  2042.       output_asm_insn ("mov%?\t%0, %1", ops);
  2043.     }
  2044.     }
  2045.  
  2046.   return "";
  2047. }
  2048.  
  2049.  
  2050. /* Output a move from arm registers to an fpu registers.
  2051.    OPERANDS[0] is an fpu register.
  2052.    OPERANDS[1] is the first registers of an arm register pair.  */
  2053.  
  2054. char *
  2055. output_mov_double_fpu_from_arm (operands)
  2056.      rtx *operands;
  2057. {
  2058.   int arm_reg0 = REGNO (operands[1]);
  2059.   rtx ops[2];
  2060.  
  2061.   if (arm_reg0 == 12)
  2062.     abort();
  2063.   ops[0] = gen_rtx (REG, SImode, arm_reg0);
  2064.   ops[1] = gen_rtx (REG, SImode, 1 + arm_reg0);
  2065.   output_asm_insn ("stm%?fd\t%|sp!, {%0, %1}", ops);
  2066.   output_asm_insn ("ldf%?d\t%0, [%|sp], #8", operands);
  2067.   return "";
  2068. }
  2069.  
  2070. /* Output a move from an fpu register to arm registers.
  2071.    OPERANDS[0] is the first registers of an arm register pair.
  2072.    OPERANDS[1] is an fpu register.  */
  2073.  
  2074. char *
  2075. output_mov_double_arm_from_fpu (operands)
  2076.      rtx *operands;
  2077. {
  2078.   int arm_reg0 = REGNO (operands[0]);
  2079.   rtx ops[2];
  2080.  
  2081.   if (arm_reg0 == 12)
  2082.     abort();
  2083.  
  2084.   ops[0] = gen_rtx (REG, SImode, arm_reg0);
  2085.   ops[1] = gen_rtx (REG, SImode, 1 + arm_reg0);
  2086.   output_asm_insn ("stf%?d\t%1, [%|sp, #-8]!", operands);
  2087.   output_asm_insn ("ldm%?fd\t%|sp!, {%0, %1}", ops);
  2088.   return "";
  2089. }
  2090.  
  2091. /* Output a move between double words.
  2092.    It must be REG<-REG, REG<-CONST_DOUBLE, REG<-CONST_INT, REG<-MEM
  2093.    or MEM<-REG and all MEMs must be offsettable addresses.  */
  2094.  
  2095. char *
  2096. output_move_double (operands)
  2097.      rtx *operands;
  2098. {
  2099.   enum rtx_code code0 = GET_CODE (operands[0]);
  2100.   enum rtx_code code1 = GET_CODE (operands[1]);
  2101.   rtx otherops[2];
  2102.  
  2103.   if (code0 == REG)
  2104.     {
  2105.       int reg0 = REGNO (operands[0]);
  2106.  
  2107.       otherops[0] = gen_rtx (REG, SImode, 1 + reg0);
  2108.       if (code1 == REG)
  2109.     {
  2110.       int reg1 = REGNO (operands[1]);
  2111.       if (reg1 == 12)
  2112.         abort();
  2113.  
  2114.       otherops[1] = gen_rtx (REG, SImode, 1 + reg1);
  2115.  
  2116.       /* Ensure the second source is not overwritten */
  2117.       if (reg0 == 1 + reg1)
  2118.         {
  2119.           output_asm_insn("mov%?\t%0, %1", otherops);
  2120.           output_asm_insn("mov%?\t%0, %1", operands);
  2121.         }
  2122.       else
  2123.         {
  2124.           output_asm_insn("mov%?\t%0, %1", operands);
  2125.           output_asm_insn("mov%?\t%0, %1", otherops);
  2126.         }
  2127.     }
  2128.       else if (code1 == CONST_DOUBLE)
  2129.     {
  2130.       otherops[1] = gen_rtx (CONST_INT, VOIDmode,
  2131.                  CONST_DOUBLE_HIGH (operands[1]));
  2132.       operands[1] = gen_rtx (CONST_INT, VOIDmode,
  2133.                  CONST_DOUBLE_LOW (operands[1]));
  2134.       output_mov_immediate (operands, FALSE, "");
  2135.       output_mov_immediate (otherops, FALSE, "");
  2136.     }
  2137.       else if (code1 == CONST_INT)
  2138.     {
  2139.       otherops[1] = const0_rtx;
  2140.       /* sign extend the intval into the high-order word */
  2141.       /* Note: output_mov_immediate may clobber operands[1], so we
  2142.          put this out first */
  2143.       if (INTVAL (operands[1]) < 0)
  2144.         output_asm_insn ("mvn%?\t%0, %1", otherops);
  2145.       else
  2146.         output_asm_insn ("mov%?\t%0, %1", otherops);
  2147.       output_mov_immediate (operands, FALSE, "");
  2148.     }
  2149.       else if (code1 == MEM)
  2150.     {
  2151.       switch (GET_CODE (XEXP (operands[1], 0)))
  2152.         {
  2153.         case REG:
  2154.           /* Handle the simple case where address is [r, #0] more
  2155.          efficient.  */
  2156.           output_asm_insn ("ldm%?ia\t%m1, %M0", operands);
  2157.           break;
  2158.           case PRE_INC:
  2159.           output_asm_insn ("add%?\t%m1, %m1, #8", operands);
  2160.           output_asm_insn ("ldm%?ia\t%m1, %M0", operands);
  2161.           break;
  2162.         case PRE_DEC:
  2163.           output_asm_insn ("sub%?\t%m1, %m1, #8", operands);
  2164.           output_asm_insn ("ldm%?ia\t%m1, %M0", operands);
  2165.           break;
  2166.         case POST_INC:
  2167.           output_asm_insn ("ldm%?ia\t%m1!, %M0", operands);
  2168.           break;
  2169.         case POST_DEC:
  2170.           output_asm_insn ("ldm%?ia\t%m1, %M0", operands);
  2171.           output_asm_insn ("sub%?\t%m1, %m1, #8", operands);
  2172.           break;
  2173.         default:
  2174.           otherops[1] = adj_offsettable_operand (operands[1], 4);
  2175.           /* Take care of overlapping base/data reg.  */
  2176.           if (reg_mentioned_p (operands[0], operands[1]))
  2177.         {
  2178.           output_asm_insn ("ldr%?\t%0, %1", otherops);
  2179.           output_asm_insn ("ldr%?\t%0, %1", operands);
  2180.         }
  2181.           else
  2182.         {
  2183.           output_asm_insn ("ldr%?\t%0, %1", operands);
  2184.           output_asm_insn ("ldr%?\t%0, %1", otherops);
  2185.         }
  2186.         }
  2187.     }
  2188.       else abort();  /* Constraints should prevent this */
  2189.     }
  2190.   else if (code0 == MEM && code1 == REG)
  2191.     {
  2192.       if (REGNO (operands[1]) == 12)
  2193.     abort();
  2194.       switch (GET_CODE (XEXP (operands[0], 0)))
  2195.         {
  2196.     case REG:
  2197.       output_asm_insn ("stm%?ia\t%m0, %M1", operands);
  2198.       break;
  2199.         case PRE_INC:
  2200.       output_asm_insn ("add%?\t%m0, %m0, #8", operands);
  2201.       output_asm_insn ("stm%?ia\t%m0, %M1", operands);
  2202.       break;
  2203.         case PRE_DEC:
  2204.       output_asm_insn ("sub%?\t%m0, %m0, #8", operands);
  2205.       output_asm_insn ("stm%?ia\t%m0, %M1", operands);
  2206.       break;
  2207.         case POST_INC:
  2208.       output_asm_insn ("stm%?ia\t%m0!, %M1", operands);
  2209.       break;
  2210.         case POST_DEC:
  2211.       output_asm_insn ("stm%?ia\t%m0, %M1", operands);
  2212.       output_asm_insn ("sub%?\t%m0, %m0, #8", operands);
  2213.       break;
  2214.         default:
  2215.       otherops[0] = adj_offsettable_operand (operands[0], 4);
  2216.       otherops[1] = gen_rtx (REG, SImode, 1 + REGNO (operands[1]));
  2217.       output_asm_insn ("str%?\t%1, %0", operands);
  2218.       output_asm_insn ("str%?\t%1, %0", otherops);
  2219.     }
  2220.     }
  2221.   else abort();  /* Constraints should prevent this */
  2222.  
  2223.   return "";
  2224. }
  2225.  
  2226.  
  2227. /* Output an arbitrary MOV reg, #n.
  2228.    OPERANDS[0] is a register.  OPERANDS[1] is a const_int.  */
  2229.  
  2230. char *
  2231. output_mov_immediate (operands)
  2232.      rtx *operands;
  2233. {
  2234.   HOST_WIDE_INT n = INTVAL (operands[1]);
  2235.   int n_ones = 0;
  2236.   int i;
  2237.  
  2238.   /* Try to use one MOV */
  2239.   if (const_ok_for_arm (n))
  2240.     {
  2241.       output_asm_insn ("mov%?\t%0, %1", operands);
  2242.       return "";
  2243.     }
  2244.  
  2245.   /* Try to use one MVN */
  2246.   if (const_ok_for_arm (~n))
  2247.     {
  2248.       operands[1] = GEN_INT (~n);
  2249.       output_asm_insn ("mvn%?\t%0, %1", operands);
  2250.       return "";
  2251.     }
  2252.  
  2253.   /* If all else fails, make it out of ORRs or BICs as appropriate. */
  2254.  
  2255.   for (i=0; i < 32; i++)
  2256.     if (n & 1 << i)
  2257.       n_ones++;
  2258.  
  2259.   if (n_ones > 16)  /* Shorter to use MVN with BIC in this case. */
  2260.     output_multi_immediate(operands, "mvn%?\t%0, %1", "bic%?\t%0, %0, %1", 1,
  2261.                ~n);
  2262.   else
  2263.     output_multi_immediate(operands, "mov%?\t%0, %1", "orr%?\t%0, %0, %1", 1,
  2264.                n);
  2265.  
  2266.   return "";
  2267. }
  2268.  
  2269.  
  2270. /* Output an ADD r, s, #n where n may be too big for one instruction.  If
  2271.    adding zero to one register, output nothing.  */
  2272.  
  2273. char *
  2274. output_add_immediate (operands)
  2275.      rtx *operands;
  2276. {
  2277.   HOST_WIDE_INT n = INTVAL (operands[2]);
  2278.  
  2279.   if (n != 0 || REGNO (operands[0]) != REGNO (operands[1]))
  2280.     {
  2281.       if (n < 0)
  2282.     output_multi_immediate (operands,
  2283.                 "sub%?\t%0, %1, %2", "sub%?\t%0, %0, %2", 2,
  2284.                 -n);
  2285.       else
  2286.     output_multi_immediate (operands,
  2287.                 "add%?\t%0, %1, %2", "add%?\t%0, %0, %2", 2,
  2288.                 n);
  2289.     }
  2290.  
  2291.   return "";
  2292. }
  2293.  
  2294. /* Output a multiple immediate operation.
  2295.    OPERANDS is the vector of operands referred to in the output patterns.
  2296.    INSTR1 is the output pattern to use for the first constant.
  2297.    INSTR2 is the output pattern to use for subsequent constants.
  2298.    IMMED_OP is the index of the constant slot in OPERANDS.
  2299.    N is the constant value.  */
  2300.  
  2301. char *
  2302. output_multi_immediate (operands, instr1, instr2, immed_op, n)
  2303.      rtx *operands;
  2304.      char *instr1, *instr2;
  2305.      int immed_op;
  2306.      HOST_WIDE_INT n;
  2307. {
  2308. #if HOST_BITS_PER_WIDE_INT > 32
  2309.   n &= 0xffffffff;
  2310. #endif
  2311.  
  2312.   if (n == 0)
  2313.     {
  2314.       operands[immed_op] = const0_rtx;
  2315.       output_asm_insn (instr1, operands); /* Quick and easy output */
  2316.     }
  2317.   else
  2318.     {
  2319.       int i;
  2320.       char *instr = instr1;
  2321.  
  2322.       /* Note that n is never zero here (which would give no output) */
  2323.       for (i = 0; i < 32; i += 2)
  2324.     {
  2325.       if (n & (3 << i))
  2326.         {
  2327.           operands[immed_op] = GEN_INT (n & (255 << i));
  2328.           output_asm_insn (instr, operands);
  2329.           instr = instr2;
  2330.           i += 6;
  2331.         }
  2332.     }
  2333.     }
  2334.   return "";
  2335. }
  2336.  
  2337.  
  2338. /* Return the appropriate ARM instruction for the operation code.
  2339.    The returned result should not be overwritten.  OP is the rtx of the
  2340.    operation.  SHIFT_FIRST_ARG is TRUE if the first argument of the operator
  2341.    was shifted.  */
  2342.  
  2343. char *
  2344. arithmetic_instr (op, shift_first_arg)
  2345.      rtx op;
  2346.      int shift_first_arg;
  2347. {
  2348.   switch (GET_CODE (op))
  2349.     {
  2350.     case PLUS:
  2351.       return "add";
  2352.  
  2353.     case MINUS:
  2354.       return shift_first_arg ? "rsb" : "sub";
  2355.  
  2356.     case IOR:
  2357.       return "orr";
  2358.  
  2359.     case XOR:
  2360.       return "eor";
  2361.  
  2362.     case AND:
  2363.       return "and";
  2364.  
  2365.     default:
  2366.       abort ();
  2367.     }
  2368. }
  2369.  
  2370.  
  2371. /* Ensure valid constant shifts and return the appropriate shift mnemonic
  2372.    for the operation code.  The returned result should not be overwritten.
  2373.    OP is the rtx code of the shift.
  2374.    On exit, *AMOUNTP will be -1 if the shift is by a register, or a constant
  2375.    shift. */
  2376.  
  2377. static char *
  2378. shift_op (op, amountp)
  2379.      rtx op;
  2380.      HOST_WIDE_INT *amountp;
  2381. {
  2382.   char *mnem;
  2383.   enum rtx_code code = GET_CODE (op);
  2384.  
  2385.   if (GET_CODE (XEXP (op, 1)) == REG || GET_CODE (XEXP (op, 1)) == SUBREG)
  2386.     *amountp = -1;
  2387.   else if (GET_CODE (XEXP (op, 1)) == CONST_INT)
  2388.     *amountp = INTVAL (XEXP (op, 1));
  2389.   else
  2390.     abort ();
  2391.  
  2392.   switch (code)
  2393.     {
  2394.     case ASHIFT:
  2395.       mnem = "asl";
  2396.       break;
  2397.  
  2398.     case ASHIFTRT:
  2399.       mnem = "asr";
  2400.       break;
  2401.  
  2402.     case LSHIFTRT:
  2403.       mnem = "lsr";
  2404.       break;
  2405.  
  2406.     case ROTATERT:
  2407.       mnem = "ror";
  2408.       break;
  2409.  
  2410.     case MULT:
  2411.       /* We never have to worry about the amount being other than a
  2412.      power of 2, since this case can never be reloaded from a reg.  */
  2413.       if (*amountp != -1)
  2414.     *amountp = int_log2 (*amountp);
  2415.       else
  2416.     abort ();
  2417.       return "asl";
  2418.  
  2419.     default:
  2420.       abort ();
  2421.     }
  2422.  
  2423.   if (*amountp != -1)
  2424.     {
  2425.       /* This is not 100% correct, but follows from the desire to merge
  2426.      multiplication by a power of 2 with the recognizer for a
  2427.      shift.  >=32 is not a valid shift for "asl", so we must try and
  2428.      output a shift that produces the correct arithmetical result.
  2429.      Using lsr #32 is identical except for the fact that the carry bit
  2430.      is not set correctly if we set the flags; but we never use the 
  2431.      carry bit from such an operation, so we can ignore that.  */
  2432.       if (code == ROTATERT)
  2433.     *amountp &= 31;        /* Rotate is just modulo 32 */
  2434.       else if (*amountp != (*amountp & 31))
  2435.     {
  2436.       if (code == ASHIFT)
  2437.         mnem = "lsr";
  2438.       *amountp = 32;
  2439.     }
  2440.  
  2441.       /* Shifts of 0 are no-ops.  */
  2442.       if (*amountp == 0)
  2443.     return NULL;
  2444.     }      
  2445.  
  2446.   return mnem;
  2447. }
  2448.  
  2449.  
  2450. /* Obtain the shift from the POWER of two. */
  2451.  
  2452. HOST_WIDE_INT
  2453. int_log2 (power)
  2454.      HOST_WIDE_INT power;
  2455. {
  2456.   HOST_WIDE_INT shift = 0;
  2457.  
  2458.   while (((1 << shift) & power) == 0)
  2459.     {
  2460.       if (shift > 31)
  2461.     abort ();
  2462.       shift++;
  2463.     }
  2464.  
  2465.   return shift;
  2466. }
  2467.  
  2468. /* Output a .ascii pseudo-op, keeping track of lengths.  This is because
  2469.    /bin/as is horribly restrictive.  */
  2470.  
  2471. void
  2472. output_ascii_pseudo_op (stream, p, len)
  2473.      FILE *stream;
  2474.      unsigned char *p;
  2475.      int len;
  2476. {
  2477.   int i;
  2478.   int len_so_far = 1000;
  2479.   int chars_so_far = 0;
  2480.  
  2481.   for (i = 0; i < len; i++)
  2482.     {
  2483.       register int c = p[i];
  2484.  
  2485.       if (len_so_far > 50)
  2486.     {
  2487.       if (chars_so_far)
  2488.         fputs ("\"\n", stream);
  2489.       fputs ("\t.ascii\t\"", stream);
  2490.       len_so_far = 0;
  2491.       arm_increase_location (chars_so_far);
  2492.       chars_so_far = 0;
  2493.     }
  2494.  
  2495.       if (c == '\"' || c == '\\')
  2496.     {
  2497.       putc('\\', stream);
  2498.       len_so_far++;
  2499.     }
  2500.  
  2501.       if (c >= ' ' && c < 0177)
  2502.     {
  2503.       putc (c, stream);
  2504.       len_so_far++;
  2505.     }
  2506.       else
  2507.     {
  2508.       fprintf (stream, "\\%03o", c);
  2509.       len_so_far +=4;
  2510.     }
  2511.  
  2512.       chars_so_far++;
  2513.     }
  2514.  
  2515.   fputs ("\"\n", stream);
  2516.   arm_increase_location (chars_so_far);
  2517. }
  2518.  
  2519.  
  2520. /* Try to determine whether a pattern really clobbers the link register.
  2521.    This information is useful when peepholing, so that lr need not be pushed
  2522.    if we combine a call followed by a return.
  2523.    NOTE: This code does not check for side-effect expressions in a SET_SRC:
  2524.    such a check should not be needed because these only update an existing
  2525.    value within a register; the register must still be set elsewhere within
  2526.    the function. */
  2527.  
  2528. static int
  2529. pattern_really_clobbers_lr (x)
  2530.      rtx x;
  2531. {
  2532.   int i;
  2533.   
  2534.   switch (GET_CODE (x))
  2535.     {
  2536.     case SET:
  2537.       switch (GET_CODE (SET_DEST (x)))
  2538.     {
  2539.     case REG:
  2540.       return REGNO (SET_DEST (x)) == 14;
  2541.  
  2542.         case SUBREG:
  2543.       if (GET_CODE (XEXP (SET_DEST (x), 0)) == REG)
  2544.         return REGNO (XEXP (SET_DEST (x), 0)) == 14;
  2545.  
  2546.       if (GET_CODE (XEXP (SET_DEST (x), 0)) == MEM)
  2547.         return 0;
  2548.       abort ();
  2549.  
  2550.         default:
  2551.       return 0;
  2552.         }
  2553.  
  2554.     case PARALLEL:
  2555.       for (i = 0; i < XVECLEN (x, 0); i++)
  2556.     if (pattern_really_clobbers_lr (XVECEXP (x, 0, i)))
  2557.       return 1;
  2558.       return 0;
  2559.  
  2560.     case CLOBBER:
  2561.       switch (GET_CODE (XEXP (x, 0)))
  2562.         {
  2563.     case REG:
  2564.       return REGNO (XEXP (x, 0)) == 14;
  2565.  
  2566.         case SUBREG:
  2567.       if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG)
  2568.         return REGNO (XEXP (XEXP (x, 0), 0)) == 14;
  2569.       abort ();
  2570.  
  2571.         default:
  2572.       return 0;
  2573.         }
  2574.  
  2575.     case UNSPEC:
  2576.       return 1;
  2577.  
  2578.     default:
  2579.       return 0;
  2580.     }
  2581. }
  2582.  
  2583. static int
  2584. function_really_clobbers_lr (first)
  2585.      rtx first;
  2586. {
  2587.   rtx insn, next;
  2588.   
  2589.   for (insn = first; insn; insn = next_nonnote_insn (insn))
  2590.     {
  2591.       switch (GET_CODE (insn))
  2592.         {
  2593.     case BARRIER:
  2594.     case NOTE:
  2595.     case CODE_LABEL:
  2596.     case JUMP_INSN:        /* Jump insns only change the PC (and conds) */
  2597.     case INLINE_HEADER:
  2598.       break;
  2599.  
  2600.         case INSN:
  2601.       if (pattern_really_clobbers_lr (PATTERN (insn)))
  2602.         return 1;
  2603.       break;
  2604.  
  2605.         case CALL_INSN:
  2606.       /* Don't yet know how to handle those calls that are not to a 
  2607.          SYMBOL_REF */
  2608.       if (GET_CODE (PATTERN (insn)) != PARALLEL)
  2609.         abort ();
  2610.  
  2611.       switch (GET_CODE (XVECEXP (PATTERN (insn), 0, 0)))
  2612.         {
  2613.         case CALL:
  2614.           if (GET_CODE (XEXP (XEXP (XVECEXP (PATTERN (insn), 0, 0), 0), 0))
  2615.           != SYMBOL_REF)
  2616.         return 1;
  2617.           break;
  2618.  
  2619.         case SET:
  2620.           if (GET_CODE (XEXP (XEXP (SET_SRC (XVECEXP (PATTERN (insn),
  2621.                               0, 0)), 0), 0))
  2622.           != SYMBOL_REF)
  2623.         return 1;
  2624.           break;
  2625.  
  2626.         default:    /* Don't recognize it, be safe */
  2627.           return 1;
  2628.         }
  2629.  
  2630.       /* A call can be made (by peepholing) not to clobber lr iff it is
  2631.          followed by a return.  There may, however, be a use insn iff
  2632.          we are returning the result of the call. 
  2633.          If we run off the end of the insn chain, then that means the
  2634.          call was at the end of the function.  Unfortunately we don't
  2635.          have a return insn for the peephole to recognize, so we
  2636.          must reject this.  (Can this be fixed by adding our own insn?) */
  2637.       if ((next = next_nonnote_insn (insn)) == NULL)
  2638.         return 1;
  2639.  
  2640.       if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == USE
  2641.           && (GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
  2642.           && (REGNO (SET_DEST (XVECEXP (PATTERN (insn), 0, 0)))
  2643.           == REGNO (XEXP (PATTERN (next), 0))))
  2644.         if ((next = next_nonnote_insn (next)) == NULL)
  2645.           return 1;
  2646.  
  2647.       if (GET_CODE (next) == JUMP_INSN
  2648.           && GET_CODE (PATTERN (next)) == RETURN)
  2649.         break;
  2650.       return 1;
  2651.  
  2652.         default:
  2653.       abort ();
  2654.         }
  2655.     }
  2656.  
  2657.   /* We have reached the end of the chain so lr was _not_ clobbered */
  2658.   return 0;
  2659. }
  2660.  
  2661. char *
  2662. output_return_instruction (operand, really_return)
  2663.      rtx operand;
  2664.      int really_return;
  2665. {
  2666.   char instr[100];
  2667.   int reg, live_regs = 0;
  2668.   int volatile_func = (optimize > 0 
  2669.                && TREE_THIS_VOLATILE (current_function_decl));
  2670.  
  2671.   return_used_this_function = 1;
  2672.  
  2673.   if (volatile_func)
  2674.     {
  2675.       rtx ops[2];
  2676.       /* If this function was declared non-returning, and we have found a tail 
  2677.      call, then we have to trust that the called function won't return. */
  2678.       if (! really_return)
  2679.     return "";
  2680.  
  2681.       /* Otherwise, trap an attempted return by aborting. */
  2682.       ops[0] = operand;
  2683.       ops[1] = gen_rtx (SYMBOL_REF, Pmode, "abort");
  2684.       output_asm_insn ("bl%d0\t%a1", ops);
  2685.       return "";
  2686.     }
  2687.       
  2688.   if (current_function_calls_alloca && ! really_return)
  2689.     abort();
  2690.     
  2691.   for (reg = 0; reg <= 10; reg++)
  2692.     if (regs_ever_live[reg] && ! call_used_regs[reg])
  2693.       live_regs++;
  2694.  
  2695.   if (live_regs || (regs_ever_live[14] && ! lr_save_eliminated))
  2696.     live_regs++;
  2697.  
  2698.   if (frame_pointer_needed)
  2699.     live_regs += 4;
  2700.  
  2701.   if (live_regs)
  2702.     {
  2703.       if (lr_save_eliminated || ! regs_ever_live[14])
  2704.         live_regs++;
  2705.  
  2706.       if (frame_pointer_needed)
  2707.         strcpy (instr, "ldm%?%d0ea\t%|fp, {");
  2708.       else
  2709.         strcpy (instr, "ldm%?%d0fd\t%|sp!, {");
  2710.  
  2711.       for (reg = 0; reg <= 10; reg++)
  2712.         if (regs_ever_live[reg] && ! call_used_regs[reg])
  2713.           {
  2714.         strcat (instr, "%|");
  2715.             strcat (instr, reg_names[reg]);
  2716.         if (--live_regs)
  2717.               strcat (instr, ", ");
  2718.           }
  2719.  
  2720.       if (frame_pointer_needed)
  2721.         {
  2722.       strcat (instr, "%|");
  2723.           strcat (instr, reg_names[11]);
  2724.           strcat (instr, ", ");
  2725.       strcat (instr, "%|");
  2726.           strcat (instr, reg_names[13]);
  2727.           strcat (instr, ", ");
  2728.       strcat (instr, "%|");
  2729.           strcat (instr, really_return ? reg_names[15] : reg_names[14]);
  2730.         }
  2731.       else
  2732.     {
  2733.       strcat (instr, "%|");
  2734.       strcat (instr, really_return ? reg_names[15] : reg_names[14]);
  2735.     }
  2736.       strcat (instr, (TARGET_6 || !really_return) ? "}" : "}^");
  2737.       output_asm_insn (instr, &operand);
  2738.     }
  2739.   else if (really_return)
  2740.     {
  2741.       strcpy (instr,
  2742.           TARGET_6 ? "mov%?%d0\t%|pc, lr" : "mov%?%d0s\t%|pc, %|lr");
  2743.       output_asm_insn (instr, &operand);
  2744.     }
  2745.  
  2746.   return "";
  2747. }
  2748.  
  2749. /* Return nonzero if optimizing and the current function is volatile.
  2750.    Such functions never return, and many memory cycles can be saved
  2751.    by not storing register values that will never be needed again.
  2752.    This optimization was added to speed up context switching in a
  2753.    kernel application. */
  2754.  
  2755. int
  2756. arm_volatile_func ()
  2757. {
  2758.   return (optimize > 0 && TREE_THIS_VOLATILE (current_function_decl));
  2759. }
  2760.  
  2761. /* Return the size of the prologue.  It's not too bad if we slightly 
  2762.    over-estimate.  */
  2763.  
  2764. static int
  2765. get_prologue_size ()
  2766. {
  2767.   return profile_flag ? 12 : 0;
  2768. }
  2769.  
  2770. /* The amount of stack adjustment that happens here, in output_return and in
  2771.    output_epilogue must be exactly the same as was calculated during reload,
  2772.    or things will point to the wrong place.  The only time we can safely
  2773.    ignore this constraint is when a function has no arguments on the stack,
  2774.    no stack frame requirement and no live registers execpt for `lr'.  If we
  2775.    can guarantee that by making all function calls into tail calls and that
  2776.    lr is not clobbered in any other way, then there is no need to push lr
  2777.    onto the stack. */
  2778.    
  2779. void
  2780. output_func_prologue (f, frame_size)
  2781.      FILE *f;
  2782.      int frame_size;
  2783. {
  2784.   int reg, live_regs_mask = 0;
  2785.   rtx operands[3];
  2786.   int volatile_func = (optimize > 0
  2787.                && TREE_THIS_VOLATILE (current_function_decl));
  2788.  
  2789.   /* Nonzero if we must stuff some register arguments onto the stack as if
  2790.      they were passed there.  */
  2791.   int store_arg_regs = 0;
  2792.  
  2793.   if (arm_ccfsm_state || arm_target_insn)
  2794.     abort ();                    /* Sanity check */
  2795.   
  2796.   return_used_this_function = 0;
  2797.   lr_save_eliminated = 0;
  2798.   
  2799.   fprintf (f, "\t%s args = %d, pretend = %d, frame = %d\n",
  2800.        ASM_COMMENT_START, current_function_args_size,
  2801.        current_function_pretend_args_size, frame_size);
  2802.   fprintf (f, "\t%s frame_needed = %d, current_function_anonymous_args = %d\n",
  2803.        ASM_COMMENT_START, frame_pointer_needed,
  2804.        current_function_anonymous_args);
  2805.  
  2806.   if (volatile_func)
  2807.     fprintf (f, "\t%s Volatile function.\n", ASM_COMMENT_START);
  2808.  
  2809.   if (current_function_anonymous_args && current_function_pretend_args_size)
  2810.     store_arg_regs = 1;
  2811.  
  2812.   for (reg = 0; reg <= 10; reg++)
  2813.     if (regs_ever_live[reg] && ! call_used_regs[reg])
  2814.       live_regs_mask |= (1 << reg);
  2815.  
  2816.   if (frame_pointer_needed)
  2817.     live_regs_mask |= 0xD800;
  2818.   else if (regs_ever_live[14])
  2819.     {
  2820.       if (! current_function_args_size
  2821.       && ! function_really_clobbers_lr (get_insns ()))
  2822.     lr_save_eliminated = 1;
  2823.       else
  2824.         live_regs_mask |= 0x4000;
  2825.     }
  2826.  
  2827.   if (live_regs_mask)
  2828.     {
  2829.       /* if a di mode load/store multiple is used, and the base register
  2830.      is r3, then r4 can become an ever live register without lr
  2831.      doing so,  in this case we need to push lr as well, or we
  2832.      will fail to get a proper return. */
  2833.  
  2834.       live_regs_mask |= 0x4000;
  2835.       lr_save_eliminated = 0;
  2836.  
  2837.     }
  2838.  
  2839.   if (lr_save_eliminated)
  2840.     fprintf (f,"\t%s I don't think this function clobbers lr\n",
  2841.          ASM_COMMENT_START);
  2842. }
  2843.  
  2844.  
  2845. void
  2846. output_func_epilogue (f, frame_size)
  2847.      FILE *f;
  2848.      int frame_size;
  2849. {
  2850.   int reg, live_regs_mask = 0, code_size = 0;
  2851.   /* If we need this then it will always be at lesat this much */
  2852.   int floats_offset = 24;
  2853.   rtx operands[3];
  2854.   int volatile_func = (optimize > 0
  2855.                && TREE_THIS_VOLATILE (current_function_decl));
  2856.  
  2857.   if (use_return_insn() && return_used_this_function)
  2858.     {
  2859.       if (frame_size && !(frame_pointer_needed || TARGET_APCS))
  2860.         {
  2861.           abort ();
  2862.         }
  2863.       goto epilogue_done;
  2864.     }
  2865.  
  2866.   /* A volatile function should never return.  Call abort.  */
  2867.   if (volatile_func)
  2868.     {
  2869.       rtx op = gen_rtx (SYMBOL_REF, Pmode, "abort");
  2870.       output_asm_insn ("bl\t%a0", &op);
  2871.       code_size = 4;
  2872.       goto epilogue_done;
  2873.     }
  2874.  
  2875.   for (reg = 0; reg <= 10; reg++)
  2876.     if (regs_ever_live[reg] && ! call_used_regs[reg])
  2877.       {
  2878.         live_regs_mask |= (1 << reg);
  2879.     floats_offset += 4;
  2880.       }
  2881.  
  2882.   if (frame_pointer_needed)
  2883.     {
  2884.       for (reg = 23; reg > 15; reg--)
  2885.     if (regs_ever_live[reg] && ! call_used_regs[reg])
  2886.       {
  2887.         fprintf (f, "\tldfe\t%s%s, [%sfp, #-%d]\n", REGISTER_PREFIX,
  2888.              reg_names[reg], REGISTER_PREFIX, floats_offset);
  2889.         floats_offset += 12;
  2890.         code_size += 4;
  2891.       }
  2892.  
  2893.       live_regs_mask |= 0xA800;
  2894.       print_multi_reg (f, "ldmea\t%sfp", live_regs_mask,
  2895.                TARGET_6 ? FALSE : TRUE);
  2896.       code_size += 4;
  2897.     }
  2898.   else
  2899.     {
  2900.       /* Restore stack pointer if necessary.  */
  2901.       if (frame_size)
  2902.     {
  2903.       operands[0] = operands[1] = stack_pointer_rtx;
  2904.       operands[2] = gen_rtx (CONST_INT, VOIDmode, frame_size);
  2905.       output_add_immediate (operands);
  2906.     }
  2907.  
  2908.       for (reg = 16; reg < 24; reg++)
  2909.     if (regs_ever_live[reg] && ! call_used_regs[reg])
  2910.       {
  2911.         fprintf (f, "\tldfe\t%s%s, [%ssp], #12\n", REGISTER_PREFIX,
  2912.              reg_names[reg], REGISTER_PREFIX);
  2913.         code_size += 4;
  2914.       }
  2915.       if (current_function_pretend_args_size == 0 && regs_ever_live[14])
  2916.     {
  2917.       print_multi_reg (f, "ldmfd\t%ssp!", live_regs_mask | 0x8000,
  2918.                TARGET_6 ? FALSE : TRUE);
  2919.       code_size += 4;
  2920.     }
  2921.       else
  2922.     {
  2923.       if (live_regs_mask || regs_ever_live[14])
  2924.         {
  2925.           live_regs_mask |= 0x4000;
  2926.           print_multi_reg (f, "ldmfd\t%ssp!", live_regs_mask, FALSE);
  2927.           code_size += 4;
  2928.         }
  2929.       if (current_function_pretend_args_size)
  2930.         {
  2931.           operands[0] = operands[1] = stack_pointer_rtx;
  2932.           operands[2] = gen_rtx (CONST_INT, VOIDmode,
  2933.                      current_function_pretend_args_size);
  2934.           output_add_immediate (operands);
  2935.         }
  2936.       fprintf (f,
  2937.            TARGET_6 ? "\tmov\t%spc, %slr\n" : "\tmovs\t%spc, %slr\n",
  2938.            REGISTER_PREFIX, REGISTER_PREFIX, f);
  2939.       code_size += 4;
  2940.     }
  2941.     }
  2942.  
  2943.  epilogue_done:
  2944.  
  2945.   /* insn_addresses isn't allocated when not optimizing */
  2946.  
  2947.   if (optimize > 0)
  2948.     arm_increase_location (code_size
  2949.                + insn_addresses[INSN_UID (get_last_insn ())]
  2950.                + get_prologue_size ());
  2951.  
  2952.   current_function_anonymous_args = 0;
  2953. }
  2954.  
  2955. static void
  2956. emit_multi_reg_push (mask)
  2957.      int mask;
  2958. {
  2959.   int num_regs = 0;
  2960.   int i, j;
  2961.   rtx par;
  2962.  
  2963.   for (i = 0; i < 16; i++)
  2964.     if (mask & (1 << i))
  2965.       num_regs++;
  2966.  
  2967.   if (num_regs == 0 || num_regs > 16)
  2968.     abort ();
  2969.  
  2970.   par = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (num_regs));
  2971.  
  2972.   for (i = 0; i < 16; i++)
  2973.     {
  2974.       if (mask & (1 << i))
  2975.     {
  2976.       XVECEXP (par, 0, 0)
  2977.         = gen_rtx (SET, VOIDmode, gen_rtx (MEM, BLKmode,
  2978.                            gen_rtx (PRE_DEC, BLKmode,
  2979.                             stack_pointer_rtx)),
  2980.                gen_rtx (UNSPEC, BLKmode,
  2981.                 gen_rtvec (1, gen_rtx (REG, SImode, i)),
  2982.                 2));
  2983.       break;
  2984.     }
  2985.     }
  2986.  
  2987.   for (j = 1, i++; j < num_regs; i++)
  2988.     {
  2989.       if (mask & (1 << i))
  2990.     {
  2991.       XVECEXP (par, 0, j)
  2992.         = gen_rtx (USE, VOIDmode, gen_rtx (REG, SImode, i));
  2993.       j++;
  2994.     }
  2995.     }
  2996.   emit_insn (par);
  2997. }
  2998.  
  2999. void
  3000. arm_expand_prologue ()
  3001. {
  3002.   int reg;
  3003.   rtx amount = GEN_INT (- get_frame_size ());
  3004.   rtx push_insn;
  3005.   int num_regs;
  3006.   int live_regs_mask = 0;
  3007.   int store_arg_regs = 0;
  3008.   int volatile_func = (optimize > 0
  3009.                && TREE_THIS_VOLATILE (current_function_decl));
  3010.  
  3011.   if (current_function_anonymous_args && current_function_pretend_args_size)
  3012.     store_arg_regs = 1;
  3013.  
  3014.   if (! volatile_func)
  3015.     for (reg = 0; reg <= 10; reg++)
  3016.       if (regs_ever_live[reg] && ! call_used_regs[reg])
  3017.     live_regs_mask |= 1 << reg;
  3018.  
  3019.   if (! volatile_func && regs_ever_live[14])
  3020.     live_regs_mask |= 0x4000;
  3021.  
  3022.   if (frame_pointer_needed)
  3023.     {
  3024.       live_regs_mask |= 0xD800;
  3025.       emit_insn (gen_movsi (gen_rtx (REG, SImode, 12),
  3026.                 stack_pointer_rtx));
  3027.     }
  3028.  
  3029.   if (current_function_pretend_args_size)
  3030.     {
  3031.       if (store_arg_regs)
  3032.     emit_multi_reg_push ((0xf0 >> (current_function_pretend_args_size / 4))
  3033.                  & 0xf);
  3034.       else
  3035.     emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, 
  3036.                    GEN_INT (-current_function_pretend_args_size)));
  3037.     }
  3038.  
  3039.   if (live_regs_mask)
  3040.     {
  3041.       /* If we have to push any regs, then we must push lr as well, or
  3042.      we won't get a proper return.  */
  3043.       live_regs_mask |= 0x4000;
  3044.       emit_multi_reg_push (live_regs_mask);
  3045.     }
  3046.       
  3047.   /* For now the integer regs are still pushed in output_func_epilogue ().  */
  3048.  
  3049.   if (! volatile_func)
  3050.     for (reg = 23; reg > 15; reg--)
  3051.       if (regs_ever_live[reg] && ! call_used_regs[reg])
  3052.     emit_insn (gen_rtx (SET, VOIDmode, 
  3053.                 gen_rtx (MEM, XFmode, 
  3054.                      gen_rtx (PRE_DEC, XFmode,
  3055.                           stack_pointer_rtx)),
  3056.                 gen_rtx (REG, XFmode, reg)));
  3057.  
  3058.   if (frame_pointer_needed)
  3059.     emit_insn (gen_addsi3 (hard_frame_pointer_rtx, gen_rtx (REG, SImode, 12),
  3060.                (GEN_INT
  3061.                 (-(4 + current_function_pretend_args_size)))));
  3062.  
  3063.   if (amount != const0_rtx)
  3064.     {
  3065.       emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, amount));
  3066.       emit_insn (gen_rtx (CLOBBER, VOIDmode, 
  3067.               gen_rtx (MEM, BLKmode, stack_pointer_rtx)));
  3068.     }
  3069.  
  3070.   /* If we are profiling, make sure no instructions are scheduled before
  3071.      the call to mcount.  */
  3072.   if (profile_flag || profile_block_flag)
  3073.     emit_insn (gen_blockage ());
  3074. }
  3075.   
  3076.  
  3077. /* If CODE is 'd', then the X is a condition operand and the instruction
  3078.    should only be executed if the condition is true.
  3079.    if CODE is 'D', then the X is a condition operand and the instruction
  3080.    should only be executed if the condition is false: however, if the mode
  3081.    of the comparison is CCFPEmode, then always execute the instruction -- we
  3082.    do this because in these circumstances !GE does not necessarily imply LT;
  3083.    in these cases the instruction pattern will take care to make sure that
  3084.    an instruction containing %d will follow, thereby undoing the effects of
  3085.    doing this instruction unconditionally.
  3086.    If CODE is 'N' then X is a floating point operand that must be negated
  3087.    before output.
  3088.    If CODE is 'B' then output a bitwise inverted value of X (a const int).
  3089.    If X is a REG and CODE is `M', output a ldm/stm style multi-reg.  */
  3090.  
  3091. void
  3092. arm_print_operand (stream, x, code)
  3093.      FILE *stream;
  3094.      rtx x;
  3095.      int code;
  3096. {
  3097.   switch (code)
  3098.     {
  3099.     case '@':
  3100.       fputs (ASM_COMMENT_START, stream);
  3101.       return;
  3102.  
  3103.     case '|':
  3104.       fputs (REGISTER_PREFIX, stream);
  3105.       return;
  3106.  
  3107.     case '?':
  3108.       if (arm_ccfsm_state == 3 || arm_ccfsm_state == 4)
  3109.     fputs (arm_condition_codes[arm_current_cc], stream);
  3110.       return;
  3111.  
  3112.     case 'N':
  3113.       {
  3114.     REAL_VALUE_TYPE r;
  3115.     REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  3116.     r = REAL_VALUE_NEGATE (r);
  3117.     fprintf (stream, "%s", fp_const_from_val (&r));
  3118.       }
  3119.       return;
  3120.  
  3121.     case 'B':
  3122.       if (GET_CODE (x) == CONST_INT)
  3123.     fprintf (stream,
  3124. #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
  3125.          "%d",
  3126. #else
  3127.          "%ld",
  3128. #endif
  3129.          ARM_SIGN_EXTEND (~ INTVAL (x)));
  3130.       else
  3131.     {
  3132.       putc ('~', stream);
  3133.       output_addr_const (stream, x);
  3134.     }
  3135.       return;
  3136.  
  3137.     case 'i':
  3138.       fprintf (stream, "%s", arithmetic_instr (x, 1));
  3139.       return;
  3140.  
  3141.     case 'I':
  3142.       fprintf (stream, "%s", arithmetic_instr (x, 0));
  3143.       return;
  3144.  
  3145.     case 'S':
  3146.       {
  3147.     HOST_WIDE_INT val;
  3148.     char *shift = shift_op (x, &val);
  3149.  
  3150.     if (shift)
  3151.       {
  3152.         fprintf (stream, ", %s ", shift_op (x, &val));
  3153.         if (val == -1)
  3154.           arm_print_operand (stream, XEXP (x, 1), 0);
  3155.         else
  3156.           fprintf (stream,
  3157. #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
  3158.                "#%d",
  3159. #else
  3160.                "#%ld",
  3161. #endif
  3162.                val);
  3163.       }
  3164.       }
  3165.       return;
  3166.  
  3167.     case 'R':
  3168.       if (REGNO (x) > 15)
  3169.     abort ();
  3170.       fputs (REGISTER_PREFIX, stream);
  3171.       fputs (reg_names[REGNO (x) + 1], stream);
  3172.       return;
  3173.  
  3174.     case 'm':
  3175.       fputs (REGISTER_PREFIX, stream);
  3176.       if (GET_CODE (XEXP (x, 0)) == REG)
  3177.     fputs (reg_names[REGNO (XEXP (x, 0))], stream);
  3178.       else
  3179.     fputs (reg_names[REGNO (XEXP (XEXP (x, 0), 0))], stream);
  3180.       return;
  3181.  
  3182.     case 'M':
  3183.       fprintf (stream, "{%s%s-%s%s}", REGISTER_PREFIX, reg_names[REGNO (x)],
  3184.            REGISTER_PREFIX, reg_names[REGNO (x) - 1
  3185.                      + ((GET_MODE_SIZE (GET_MODE (x))
  3186.                          + GET_MODE_SIZE (SImode) - 1)
  3187.                         / GET_MODE_SIZE (SImode))]);
  3188.       return;
  3189.  
  3190.     case 'd':
  3191.       if (x)
  3192.         fputs (arm_condition_codes[get_arm_condition_code (x)],
  3193.            stream);
  3194.       return;
  3195.  
  3196.     case 'D':
  3197.       if (x && (flag_fast_math
  3198.         || GET_CODE (x) == EQ || GET_CODE (x) == NE
  3199.         || (GET_MODE (XEXP (x, 0)) != CCFPEmode
  3200.             && (GET_MODE_CLASS (GET_MODE (XEXP (x, 0)))
  3201.             != MODE_FLOAT))))
  3202.         fputs (arm_condition_codes[ARM_INVERSE_CONDITION_CODE
  3203.                    (get_arm_condition_code (x))],
  3204.            stream);
  3205.       return;
  3206.  
  3207.     default:
  3208.       if (x == 0)
  3209.     abort ();
  3210.  
  3211.       if (GET_CODE (x) == REG)
  3212.     {
  3213.       fputs (REGISTER_PREFIX, stream);
  3214.       fputs (reg_names[REGNO (x)], stream);
  3215.     }
  3216.       else if (GET_CODE (x) == MEM)
  3217.     {
  3218.       output_memory_reference_mode = GET_MODE (x);
  3219.       output_address (XEXP (x, 0));
  3220.     }
  3221.       else if (GET_CODE (x) == CONST_DOUBLE)
  3222.     fprintf (stream, "#%s", fp_immediate_constant (x));
  3223.       else if (GET_CODE (x) == NEG)
  3224.     abort (); /* This should never happen now. */
  3225.       else
  3226.     {
  3227.       fputc ('#', stream);
  3228.       output_addr_const (stream, x);
  3229.     }
  3230.     }
  3231. }
  3232.  
  3233. /* Increase the `arm_text_location' by AMOUNT if we're in the text
  3234.    segment.  */
  3235.  
  3236. void
  3237. arm_increase_location (amount)
  3238.      int amount;
  3239. {
  3240.   if (in_text_section ())
  3241.     arm_text_location += amount;
  3242. }
  3243.  
  3244.  
  3245. /* Output a label definition.  If this label is within the .text segment, it
  3246.    is stored in OFFSET_TABLE, to be used when building `llc' instructions.
  3247.    Maybe GCC remembers names not starting with a `*' for a long time, but this
  3248.    is a minority anyway, so we just make a copy.  Do not store the leading `*'
  3249.    if the name starts with one.  */
  3250.  
  3251. void
  3252. arm_asm_output_label (stream, name)
  3253.      FILE *stream;
  3254.      char *name;
  3255. {
  3256.   char *real_name, *s;
  3257.   struct label_offset *cur;
  3258.   int hash = 0;
  3259.  
  3260.   assemble_name (stream, name);
  3261.   fputs (":\n", stream);
  3262.   if (! in_text_section ())
  3263.     return;
  3264.  
  3265.   if (name[0] == '*')
  3266.     {
  3267.       real_name = xmalloc (1 + strlen (&name[1]));
  3268.       strcpy (real_name, &name[1]);
  3269.     }
  3270.   else
  3271.     {
  3272.       real_name = xmalloc (2 + strlen (name));
  3273.       strcpy (real_name, USER_LABEL_PREFIX);
  3274.       strcat (real_name, name);
  3275.     }
  3276.   for (s = real_name; *s; s++)
  3277.     hash += *s;
  3278.  
  3279.   hash = hash % LABEL_HASH_SIZE;
  3280.   cur = (struct label_offset *) xmalloc (sizeof (struct label_offset));
  3281.   cur->name = real_name;
  3282.   cur->offset = arm_text_location;
  3283.   cur->cdr = offset_table[hash];
  3284.   offset_table[hash] = cur;
  3285. }
  3286.  
  3287. /* Load a symbol that is known to be in the text segment into a register.
  3288.    This should never be called when not optimizing.  */
  3289.  
  3290. char *
  3291. output_load_symbol (insn, operands)
  3292.      rtx insn;
  3293.      rtx *operands;
  3294. {
  3295.   char *s;
  3296.   char *name = XSTR (operands[1], 0);
  3297.   struct label_offset *he;
  3298.   int hash = 0;
  3299.   int offset;
  3300.   unsigned int mask, never_mask = 0xffffffff;
  3301.   int shift, inst;
  3302.   char buffer[100];
  3303.  
  3304.   if (optimize == 0 || *name != '*')
  3305.     abort ();
  3306.  
  3307.   for (s = &name[1]; *s; s++)
  3308.     hash += *s;
  3309.  
  3310.   hash = hash % LABEL_HASH_SIZE;
  3311.   he = offset_table[hash];
  3312.   while (he && strcmp (he->name, &name[1]))
  3313.     he = he->cdr;
  3314.   
  3315.   if (!he)
  3316.     abort ();
  3317.   
  3318.   offset = (arm_text_location + insn_addresses[INSN_UID (insn)]
  3319.         + get_prologue_size () + 8 - he->offset);
  3320.   if (offset < 0)
  3321.     abort ();
  3322.  
  3323.   /* When generating the instructions, we never mask out the bits that we
  3324.      think will be always zero, then if a mistake has occurred somewhere, the
  3325.      assembler will spot it and generate an error.  */
  3326.  
  3327.   /* If the symbol is word aligned then we might be able to reduce the
  3328.      number of loads.  */
  3329.   shift = ((offset & 3) == 0) ? 2 : 0;
  3330.  
  3331.   /* Clear the bits from NEVER_MASK that will be orred in with the individual
  3332.      instructions.  */
  3333.   for (; shift < 32; shift += 8)
  3334.     {
  3335.       mask = 0xff << shift;
  3336.       if ((offset & mask) || ((unsigned) offset) > mask)
  3337.     never_mask &= ~mask;
  3338.     }
  3339.  
  3340.   inst = 8;
  3341.   mask = 0xff << (shift - 32);
  3342.  
  3343.   while (mask && (never_mask & mask) == 0)
  3344.     {
  3345.       if (inst == 8)
  3346.     {
  3347.       strcpy (buffer, "sub%?\t%0, %|pc, #(8 + . -%a1)");
  3348.       if ((never_mask | mask) != 0xffffffff)
  3349.         sprintf (buffer + strlen (buffer), " & 0x%x", mask | never_mask);
  3350.     }
  3351.       else
  3352.     sprintf (buffer, "sub%%?\t%%0, %%0, #(%d + . -%%a1) & 0x%x",
  3353.          inst, mask | never_mask);
  3354.  
  3355.       output_asm_insn (buffer, operands);
  3356.       mask <<= 8;
  3357.       inst -= 4;
  3358.     }
  3359.  
  3360.   return "";
  3361. }
  3362.  
  3363. /* Output code resembling an .lcomm directive.  /bin/as doesn't have this
  3364.    directive hence this hack, which works by reserving some `.space' in the
  3365.    bss segment directly.
  3366.  
  3367.    XXX This is a severe hack, which is guaranteed NOT to work since it doesn't
  3368.    define STATIC COMMON space but merely STATIC BSS space.  */
  3369.  
  3370. void
  3371. output_lcomm_directive (stream, name, size, rounded)
  3372.      FILE *stream;
  3373.      char *name;
  3374.      int size, rounded;
  3375. {
  3376.   fprintf (stream, "\n\t.bss\t%s .lcomm\n", ASM_COMMENT_START);
  3377.   assemble_name (stream, name);
  3378.   fprintf (stream, ":\t.space\t%d\n", rounded);
  3379.   if (in_text_section ())
  3380.     fputs ("\n\t.text\n", stream);
  3381.   else
  3382.     fputs ("\n\t.data\n", stream);
  3383. }
  3384.  
  3385. /* A finite state machine takes care of noticing whether or not instructions
  3386.    can be conditionally executed, and thus decrease execution time and code
  3387.    size by deleting branch instructions.  The fsm is controlled by
  3388.    final_prescan_insn, and controls the actions of ASM_OUTPUT_OPCODE.  */
  3389.  
  3390. /* The state of the fsm controlling condition codes are:
  3391.    0: normal, do nothing special
  3392.    1: make ASM_OUTPUT_OPCODE not output this instruction
  3393.    2: make ASM_OUTPUT_OPCODE not output this instruction
  3394.    3: make instructions conditional
  3395.    4: make instructions conditional
  3396.  
  3397.    State transitions (state->state by whom under condition):
  3398.    0 -> 1 final_prescan_insn if the `target' is a label
  3399.    0 -> 2 final_prescan_insn if the `target' is an unconditional branch
  3400.    1 -> 3 ASM_OUTPUT_OPCODE after not having output the conditional branch
  3401.    2 -> 4 ASM_OUTPUT_OPCODE after not having output the conditional branch
  3402.    3 -> 0 ASM_OUTPUT_INTERNAL_LABEL if the `target' label is reached
  3403.           (the target label has CODE_LABEL_NUMBER equal to arm_target_label).
  3404.    4 -> 0 final_prescan_insn if the `target' unconditional branch is reached
  3405.           (the target insn is arm_target_insn).
  3406.  
  3407.    If the jump clobbers the conditions then we use states 2 and 4.
  3408.  
  3409.    A similar thing can be done with conditional return insns.
  3410.  
  3411.    XXX In case the `target' is an unconditional branch, this conditionalising
  3412.    of the instructions always reduces code size, but not always execution
  3413.    time.  But then, I want to reduce the code size to somewhere near what
  3414.    /bin/cc produces.  */
  3415.  
  3416. /* Returns the index of the ARM condition code string in
  3417.    `arm_condition_codes'.  COMPARISON should be an rtx like
  3418.    `(eq (...) (...))'.  */
  3419.  
  3420. int
  3421. get_arm_condition_code (comparison)
  3422.      rtx comparison;
  3423. {
  3424.   switch (GET_CODE (comparison))
  3425.     {
  3426.     case NE: return (1);
  3427.     case EQ: return (0);
  3428.     case GE: return (10);
  3429.     case GT: return (12);
  3430.     case LE: return (13);
  3431.     case LT: return (11);
  3432.     case GEU: return (2);
  3433.     case GTU: return (8);
  3434.     case LEU: return (9);
  3435.     case LTU: return (3);
  3436.     default: abort ();
  3437.     }
  3438.   /*NOTREACHED*/
  3439.   return (42);
  3440. }
  3441.  
  3442.  
  3443. void
  3444. final_prescan_insn (insn, opvec, noperands)
  3445.      rtx insn;
  3446.      rtx *opvec;
  3447.      int noperands;
  3448. {
  3449.   /* BODY will hold the body of INSN.  */
  3450.   register rtx body = PATTERN (insn);
  3451.  
  3452.   /* This will be 1 if trying to repeat the trick, and things need to be
  3453.      reversed if it appears to fail.  */
  3454.   int reverse = 0;
  3455.  
  3456.   /* JUMP_CLOBBERS will be one implies that the conditions if a branch is
  3457.      taken are clobbered, even if the rtl suggests otherwise.  It also
  3458.      means that we have to grub around within the jump expression to find
  3459.      out what the conditions are when the jump isn't taken.  */
  3460.   int jump_clobbers = 0;
  3461.   
  3462.   /* If we start with a return insn, we only succeed if we find another one. */
  3463.   int seeking_return = 0;
  3464.   
  3465.   /* START_INSN will hold the insn from where we start looking.  This is the
  3466.      first insn after the following code_label if REVERSE is true.  */
  3467.   rtx start_insn = insn;
  3468.  
  3469.   /* If in state 4, check if the target branch is reached, in order to
  3470.      change back to state 0.  */
  3471.   if (arm_ccfsm_state == 4)
  3472.     {
  3473.       if (insn == arm_target_insn)
  3474.       {
  3475.     arm_target_insn = NULL;
  3476.     arm_ccfsm_state = 0;
  3477.       }
  3478.       return;
  3479.     }
  3480.  
  3481.   /* If in state 3, it is possible to repeat the trick, if this insn is an
  3482.      unconditional branch to a label, and immediately following this branch
  3483.      is the previous target label which is only used once, and the label this
  3484.      branch jumps to is not too far off.  */
  3485.   if (arm_ccfsm_state == 3)
  3486.     {
  3487.       if (simplejump_p (insn))
  3488.     {
  3489.       start_insn = next_nonnote_insn (start_insn);
  3490.       if (GET_CODE (start_insn) == BARRIER)
  3491.         {
  3492.           /* XXX Isn't this always a barrier?  */
  3493.           start_insn = next_nonnote_insn (start_insn);
  3494.         }
  3495.       if (GET_CODE (start_insn) == CODE_LABEL
  3496.           && CODE_LABEL_NUMBER (start_insn) == arm_target_label
  3497.           && LABEL_NUSES (start_insn) == 1)
  3498.         reverse = TRUE;
  3499.       else
  3500.         return;
  3501.     }
  3502.       else if (GET_CODE (body) == RETURN)
  3503.         {
  3504.       start_insn = next_nonnote_insn (start_insn);
  3505.       if (GET_CODE (start_insn) == BARRIER)
  3506.         start_insn = next_nonnote_insn (start_insn);
  3507.       if (GET_CODE (start_insn) == CODE_LABEL
  3508.           && CODE_LABEL_NUMBER (start_insn) == arm_target_label
  3509.           && LABEL_NUSES (start_insn) == 1)
  3510.         {
  3511.           reverse = TRUE;
  3512.           seeking_return = 1;
  3513.         }
  3514.       else
  3515.         return;
  3516.         }
  3517.       else
  3518.     return;
  3519.     }
  3520.  
  3521.   if (arm_ccfsm_state != 0 && !reverse)
  3522.     abort ();
  3523.   if (GET_CODE (insn) != JUMP_INSN)
  3524.     return;
  3525.  
  3526.   /* This jump might be paralleled with a clobber of the condition codes 
  3527.      the jump should always come first */
  3528.   if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) > 0)
  3529.     body = XVECEXP (body, 0, 0);
  3530.  
  3531. #if 0  
  3532.   /* If this is a conditional return then we don't want to know */
  3533.   if (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC
  3534.       && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
  3535.       && (GET_CODE (XEXP (SET_SRC (body), 1)) == RETURN
  3536.           || GET_CODE (XEXP (SET_SRC (body), 2)) == RETURN))
  3537.     return;
  3538. #endif
  3539.  
  3540.   if (reverse
  3541.       || (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC
  3542.       && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE))
  3543.     {
  3544.       int insns_skipped = 0, fail = FALSE, succeed = FALSE;
  3545.       /* Flag which part of the IF_THEN_ELSE is the LABEL_REF.  */
  3546.       int then_not_else = TRUE;
  3547.       rtx this_insn = start_insn, label = 0;
  3548.  
  3549.       if (get_attr_conds (insn) == CONDS_JUMP_CLOB)
  3550.     {
  3551.       /* The code below is wrong for these, and I haven't time to
  3552.          fix it now.  So we just do the safe thing and return.  This
  3553.          whole function needs re-writing anyway.  */
  3554.       jump_clobbers = 1;
  3555.       return;
  3556.     }
  3557.       
  3558.       /* Register the insn jumped to.  */
  3559.       if (reverse)
  3560.         {
  3561.       if (!seeking_return)
  3562.         label = XEXP (SET_SRC (body), 0);
  3563.         }
  3564.       else if (GET_CODE (XEXP (SET_SRC (body), 1)) == LABEL_REF)
  3565.     label = XEXP (XEXP (SET_SRC (body), 1), 0);
  3566.       else if (GET_CODE (XEXP (SET_SRC (body), 2)) == LABEL_REF)
  3567.     {
  3568.       label = XEXP (XEXP (SET_SRC (body), 2), 0);
  3569.       then_not_else = FALSE;
  3570.     }
  3571.       else if (GET_CODE (XEXP (SET_SRC (body), 1)) == RETURN)
  3572.     seeking_return = 1;
  3573.       else if (GET_CODE (XEXP (SET_SRC (body), 2)) == RETURN)
  3574.         {
  3575.       seeking_return = 1;
  3576.       then_not_else = FALSE;
  3577.         }
  3578.       else
  3579.     abort ();
  3580.  
  3581.       /* See how many insns this branch skips, and what kind of insns.  If all
  3582.      insns are okay, and the label or unconditional branch to the same
  3583.      label is not too far away, succeed.  */
  3584.       for (insns_skipped = 0;
  3585.        !fail && !succeed && insns_skipped < MAX_INSNS_SKIPPED;
  3586.        insns_skipped++)
  3587.     {
  3588.       rtx scanbody;
  3589.  
  3590.       this_insn = next_nonnote_insn (this_insn);
  3591.       if (!this_insn)
  3592.         break;
  3593.  
  3594.       scanbody = PATTERN (this_insn);
  3595.  
  3596.       switch (GET_CODE (this_insn))
  3597.         {
  3598.         case CODE_LABEL:
  3599.           /* Succeed if it is the target label, otherwise fail since
  3600.          control falls in from somewhere else.  */
  3601.           if (this_insn == label)
  3602.         {
  3603.           if (jump_clobbers)
  3604.             {
  3605.               arm_ccfsm_state = 2;
  3606.               this_insn = next_nonnote_insn (this_insn);
  3607.             }
  3608.           else
  3609.             arm_ccfsm_state = 1;
  3610.           succeed = TRUE;
  3611.         }
  3612.           else
  3613.         fail = TRUE;
  3614.           break;
  3615.  
  3616.         case BARRIER:
  3617.           /* Succeed if the following insn is the target label.
  3618.          Otherwise fail.  
  3619.          If return insns are used then the last insn in a function 
  3620.          will be a barrier. */
  3621.           this_insn = next_nonnote_insn (this_insn);
  3622.           if (this_insn && this_insn == label)
  3623.         {
  3624.           if (jump_clobbers)
  3625.             {
  3626.               arm_ccfsm_state = 2;
  3627.               this_insn = next_nonnote_insn (this_insn);
  3628.             }
  3629.           else
  3630.             arm_ccfsm_state = 1;
  3631.           succeed = TRUE;
  3632.         }
  3633.           else
  3634.         fail = TRUE;
  3635.           break;
  3636.  
  3637.         case CALL_INSN:
  3638.           /* The arm 6xx uses full 32 bit addresses so the cc is not 
  3639.          preserved over calls */
  3640.           if (TARGET_6)
  3641.         fail = TRUE;
  3642.           break;
  3643.         case JUMP_INSN:
  3644.                 /* If this is an unconditional branch to the same label, succeed.
  3645.          If it is to another label, do nothing.  If it is conditional,
  3646.          fail.  */
  3647.           /* XXX Probably, the test for the SET and the PC are unnecessary. */
  3648.  
  3649.           if (GET_CODE (scanbody) == SET
  3650.           && GET_CODE (SET_DEST (scanbody)) == PC)
  3651.         {
  3652.           if (GET_CODE (SET_SRC (scanbody)) == LABEL_REF
  3653.               && XEXP (SET_SRC (scanbody), 0) == label && !reverse)
  3654.             {
  3655.               arm_ccfsm_state = 2;
  3656.               succeed = TRUE;
  3657.             }
  3658.           else if (GET_CODE (SET_SRC (scanbody)) == IF_THEN_ELSE)
  3659.             fail = TRUE;
  3660.         }
  3661.           else if (GET_CODE (scanbody) == RETURN
  3662.                && seeking_return)
  3663.             {
  3664.           arm_ccfsm_state = 2;
  3665.           succeed = TRUE;
  3666.             }
  3667.           else if (GET_CODE (scanbody) == PARALLEL)
  3668.             {
  3669.           switch (get_attr_conds (this_insn))
  3670.             {
  3671.             case CONDS_NOCOND:
  3672.               break;
  3673.             default:
  3674.               fail = TRUE;
  3675.               break;
  3676.             }
  3677.         }
  3678.           break;
  3679.  
  3680.         case INSN:
  3681.           /* Instructions using or affecting the condition codes make it
  3682.          fail.  */
  3683.           if ((GET_CODE (scanbody) == SET
  3684.            || GET_CODE (scanbody) == PARALLEL)
  3685.           && get_attr_conds (this_insn) != CONDS_NOCOND)
  3686.         fail = TRUE;
  3687.           break;
  3688.  
  3689.         default:
  3690.           break;
  3691.         }
  3692.     }
  3693.       if (succeed)
  3694.     {
  3695.       if ((!seeking_return) && (arm_ccfsm_state == 1 || reverse))
  3696.         arm_target_label = CODE_LABEL_NUMBER (label);
  3697.       else if (seeking_return || arm_ccfsm_state == 2)
  3698.         {
  3699.           while (this_insn && GET_CODE (PATTERN (this_insn)) == USE)
  3700.             {
  3701.           this_insn = next_nonnote_insn (this_insn);
  3702.           if (this_insn && (GET_CODE (this_insn) == BARRIER
  3703.                     || GET_CODE (this_insn) == CODE_LABEL))
  3704.             abort ();
  3705.             }
  3706.           if (!this_insn)
  3707.             {
  3708.           /* Oh, dear! we ran off the end.. give up */
  3709.           recog (PATTERN (insn), insn, NULL_PTR);
  3710.           arm_ccfsm_state = 0;
  3711.           arm_target_insn = NULL;
  3712.           return;
  3713.             }
  3714.           arm_target_insn = this_insn;
  3715.         }
  3716.       else
  3717.         abort ();
  3718.       if (jump_clobbers)
  3719.         {
  3720.           if (reverse)
  3721.         abort ();
  3722.           arm_current_cc = 
  3723.           get_arm_condition_code (XEXP (XEXP (XEXP (SET_SRC (body),
  3724.                                 0), 0), 1));
  3725.           if (GET_CODE (XEXP (XEXP (SET_SRC (body), 0), 0)) == AND)
  3726.         arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
  3727.           if (GET_CODE (XEXP (SET_SRC (body), 0)) == NE)
  3728.         arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
  3729.         }
  3730.       else
  3731.         {
  3732.           /* If REVERSE is true, ARM_CURRENT_CC needs to be inverted from
  3733.          what it was.  */
  3734.           if (!reverse)
  3735.         arm_current_cc = get_arm_condition_code (XEXP (SET_SRC (body),
  3736.                                    0));
  3737.         }
  3738.  
  3739.       if (reverse || then_not_else)
  3740.         arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
  3741.     }
  3742.       /* restore recog_operand (getting the attributes of other insns can
  3743.      destroy this array, but final.c assumes that it remains intact
  3744.      across this call; since the insn has been recognized already we
  3745.      call recog direct). */
  3746.       recog (PATTERN (insn), insn, NULL_PTR);
  3747.     }
  3748. }
  3749.  
  3750. /* EOF */
  3751.